Repository: pyjanitor-devs/pyjanitor

Issue:
test_dict_extension_array fails on CI
In working on the MkDocs build (#897), I found that the function `test_dict_extension_array` fails. I marked it as `xfail` for the time being to prevent it from being a blocker. Meanwhile, I am raising this issue to bring it to the attention of @samukweku. The error is reproducible because I have also added in the decorator (`@reproduce_failure("6.23.4", b"AAEAAAEAAAAB")`) on top of it.


Discussion:

Resolving patch:
diff --git a/janitor/functions/utils.py b/janitor/functions/utils.py
--- a/janitor/functions/utils.py
+++ b/janitor/functions/utils.py
@@ -213,6 +213,14 @@ def _select_column_names(columns_to_select, df):
     raise TypeError("This type is not supported in column selection.")
 
 
+# hack to get it to recognize typing.Pattern
+# functools.singledispatch does not natively
+# recognize types from the typing module
+# `type(re.compile(r"\d+"))` returns re.Pattern
+# which is a type and functools.singledispatch
+# accepts it without drama;
+# however, the same type from typing.Pattern
+# is not accepted.
 @_select_column_names.register(type(re.compile(r"\d+")))  # noqa: F811
 def _column_sel_dispatch(columns_to_select, df):  # noqa: F811
     """
diff --git a/janitor/utils.py b/janitor/utils.py
--- a/janitor/utils.py
+++ b/janitor/utils.py
@@ -428,13 +428,3 @@ def is_connected(url: str) -> bool:
         )
         raise e
     return False
-
-
-# hack to get it to recognize typing.Pattern
-# functools.singledispatch does not natively
-# recognize types from the typing module
-# `type(re.compile(r"\d+"))` returns re.Pattern
-# which is a type and functools.singledispatch
-# accepts it without drama;
-# however, the same type from typing.Pattern
-# is not accepted.


Test patch:
diff --git a/tests/functions/test_complete.py b/tests/functions/test_complete.py
--- a/tests/functions/test_complete.py
+++ b/tests/functions/test_complete.py
@@ -1,4 +1,3 @@
-from hypothesis.core import reproduce_failure
 import numpy as np
 import pandas as pd
 import pytest
@@ -153,9 +152,10 @@ def test_dict(df):
     assert_frame_equal(result, expected)
 
 
-@pytest.mark.xfail(reason="Failing on CI; need to fix.")
+@pytest.mark.xfail(
+    reason="CI failure due to dtype mismatch. Tests successful locally."
+)
 @given(df=categoricaldf_strategy())
-@reproduce_failure("6.23.4", b"AAEAAAEAAAAB")
 def test_dict_extension_array(df):
     """
     Test `complete` output when *columns
@@ -165,18 +165,15 @@ def test_dict_extension_array(df):
     cols = ["names", "numbers"]
     df = df.assign(names=[*ascii_lowercase[: len(df)]])
     new_numbers = range(df.numbers.min(), df.numbers.max() + 1)
-    new_numbers = pd.array(new_numbers)
-    new_numbers = {"numbers": new_numbers}
-    cols = ["numbers", "names"]
-    result = df.complete(new_numbers, "names", sort=True)
-    columns = df.columns
-    new_index = range(df.numbers.min(), df.numbers.max() + 1)
-    new_index = pd.MultiIndex.from_product([new_index, df.names], names=cols)
+    new_index = pd.MultiIndex.from_product([df.names, new_numbers], names=cols)
+    new_numbers = {"numbers": pd.array(new_numbers)}
+    result = df.complete("names", new_numbers, sort=True)
+
     expected = (
         df.set_index(cols)
         .reindex(new_index)
         .reset_index()
-        .reindex(columns=columns)
+        .reindex(columns=df.columns)
     )
 
     assert_frame_equal(result, expected)