Repository: pyjanitor-devs/pyjanitor

Issue:
[TST/BUG] System compatibility, test cases failed on window and macos
Closes #1143.

Well, there has another problem which is **system compatibility**.
Base on https://github.com/pyjanitor-devs/pyjanitor/actions/runs/2897129896

- Ubuntu all passed.
- Window all failed, need to ignore dtype
- MacOS all failed, data generation slowly

Window:

Problems are easily fixed on window. All failed on dtype.
```python
____________________________ test_extension_array _____________________________
[gw0] win32 -- Python 3.10.5 C:\Miniconda3\envs\test\python.exe

    def test_extension_array():
        """Test output on an extension array"""
        others = dict(
            id=pd.Categorical(
                values=(2, 1, 1, 2, 1), categories=(1, 2, 3), ordered=True
            ),
            year=(2018, 2018, 2019, 2020, 2020),
            gender=pd.Categorical(("female", "male", "male", "female", "male")),
        )
    
        expected = expand_grid(others=others).droplevel(axis=1, level=-1)
        others = [pd.Series(val).rename(key) for key, val in others.items()]
    
        func = lambda x, y: pd.merge(x, y, how="cross")  # noqa: E731
        actual = reduce(func, others)
>       assert_frame_equal(expected, actual)
E       AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="year") are different
E       
E       Attribute "dtype" are different
E       [left]:  int32
E       [right]: int64

tests\functions\test_expand_grid.py:345: AssertionError
```

MacOS:

```python
_____________________________ test_default_length ______________________________
[gw0] darwin -- Python 3.10.5 /Users/runner/miniconda3/envs/test/bin/python

    @given(df=df_strategy())
>   def test_default_length(df):
E   hypothesis.errors.FailedHealthCheck: Data generation is extremely slow: Only produced 4 valid examples in 1.00 seconds (7 invalid ones and 1 exceeded maximum size). Try decreasing size of the data you're generating (with e.g. max_size or max_leaves parameters).
E   See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.too_slow to the suppress_health_check settings for this test.

tests/functions/test_case_when.py:79: FailedHealthCheck
```


Discussion:
@Zeroto521 I observe that sometimes too when running on Mac on the docket installation, I suggest we turn off the health checks - https://github.com/HypothesisWorks/hypothesis/issues/2195#issuecomment-557451955

Resolving patch:
diff --git a/janitor/biology.py b/janitor/biology.py
--- a/janitor/biology.py
+++ b/janitor/biology.py
@@ -57,13 +57,13 @@ def join_fasta(
         >>> df = pd.DataFrame({"sequence_accession":
         ... ["SEQUENCE_1", "SEQUENCE_2", ]})
 
-        >>> df = df.join_fasta(
+        >>> df = df.join_fasta(  # doctest: +SKIP
         ...     filename=tf.name,
         ...     id_col='sequence_accession',
         ...     column_name='sequence',
         ... )
 
-        >>> df.sequence
+        >>> df.sequence  # doctest: +SKIP
         0    MTEITAAMVKELRESTGAGMMDCK
         1           SATVSEINSETDFVAKN
         Name: sequence, dtype: object
diff --git a/janitor/functions/utils.py b/janitor/functions/utils.py
--- a/janitor/functions/utils.py
+++ b/janitor/functions/utils.py
@@ -243,10 +243,13 @@ def _column_sel_dispatch(columns_to_select, df):  # noqa: F811
     if _is_str_or_cat(df_columns):
         if columns_to_select in df_columns:
             return [columns_to_select]
-        outcome = fnmatch.filter(df_columns, columns_to_select)
-        if not outcome:
+        # fix for Github Issue 1160
+        outcome = [
+            fnmatch.fnmatchcase(column, columns_to_select) for column in df
+        ]
+        if not any(outcome):
             raise KeyError(f"No match was returned for '{columns_to_select}'.")
-        return outcome
+        return df_columns[outcome]
 
     if is_datetime64_dtype(df_columns):
         timestamp = df_columns.get_loc(columns_to_select)
diff --git a/janitor/math.py b/janitor/math.py
--- a/janitor/math.py
+++ b/janitor/math.py
@@ -299,11 +299,11 @@ def ecdf(s: pd.Series) -> Tuple[np.ndarray, np.ndarray]:
 
         >>> import pandas as pd
         >>> import janitor
-        >>> df = pd.DataFrame({"numbers": [0, 4, 0, 1, 2, 1, 1, 3]})
-        >>> x, y = df["numbers"].ecdf()
-        >>> x
+        >>> s = pd.Series([0, 4, 0, 1, 2, 1, 1, 3])
+        >>> x, y = s.ecdf()
+        >>> x  # doctest: +SKIP
         array([0, 0, 1, 1, 1, 2, 3, 4])
-        >>> y
+        >>> y  # doctest: +SKIP
         array([0.125, 0.25 , 0.375, 0.5  , 0.625, 0.75 , 0.875, 1.   ])
 
     :param s: A pandas series. `dtype` should be numeric.


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
@@ -489,7 +489,7 @@ def test_explicit_scalar(fill_df):
         .reindex(columns=fill_df.columns)
         .sort_values(columns, ignore_index=True)
     )
-    assert_frame_equal(result, expected)
+    assert_frame_equal(result, expected, check_dtype=False)
 
 
 def test_explicit_scalar_cat(fill_df):
@@ -521,7 +521,7 @@ def test_explicit_scalar_cat(fill_df):
             }
         )
     )
-    assert_frame_equal(result, expected)
+    assert_frame_equal(result, expected, check_dtype=False)
 
 
 # https://tidyr.tidyverse.org/reference/complete.html
@@ -595,7 +595,7 @@ def test_explicit_dict(fill_df):
         ]
     )
 
-    assert_frame_equal(result, expected)
+    assert_frame_equal(result, expected, check_dtype=False)
 
 
 def test_explicit_(fill_df):
diff --git a/tests/functions/test_expand_grid.py b/tests/functions/test_expand_grid.py
--- a/tests/functions/test_expand_grid.py
+++ b/tests/functions/test_expand_grid.py
@@ -164,7 +164,7 @@ def test_numpy_2d(df):
     expected.columns = pd.MultiIndex.from_arrays(
         [["A", "B", "B"], expected.columns]
     )
-    assert_frame_equal(result, expected)
+    assert_frame_equal(result, expected, check_dtype=False)
 
 
 @settings(deadline=None)
@@ -272,7 +272,7 @@ def test_sequence(df):
     expected.columns = pd.MultiIndex.from_arrays(
         [["A", "B"], expected.columns]
     )
-    assert_frame_equal(result, expected)
+    assert_frame_equal(result, expected, check_dtype=False)
 
 
 @settings(deadline=None)
@@ -290,7 +290,7 @@ def test_scalar(df):
     expected.columns = pd.MultiIndex.from_arrays(
         [["A", "B"], expected.columns]
     )
-    assert_frame_equal(result, expected)
+    assert_frame_equal(result, expected, check_dtype=False)
 
 
 @settings(deadline=None)
@@ -342,4 +342,4 @@ def test_extension_array():
 
     func = lambda x, y: pd.merge(x, y, how="cross")  # noqa: E731
     actual = reduce(func, others)
-    assert_frame_equal(expected, actual)
+    assert_frame_equal(expected, actual, check_dtype=False)
diff --git a/tests/functions/test_pivot_longer.py b/tests/functions/test_pivot_longer.py
--- a/tests/functions/test_pivot_longer.py
+++ b/tests/functions/test_pivot_longer.py
@@ -530,7 +530,7 @@ def test_names_pat_str(df_checks):
         df_checks, stubnames="ht", i=["famid", "birth"], j="age"
     ).reset_index()
 
-    assert_frame_equal(result, actual)
+    assert_frame_equal(result, actual, check_dtype=False)
 
 
 def test_multiindex_column_level(df_multi):
@@ -897,7 +897,7 @@ def test_multiple_dot_value():
         .reset_index()
     )
 
-    assert_frame_equal(result, actual)
+    assert_frame_equal(result, actual, check_dtype=False)
 
 
 @pytest.fixture
diff --git a/tests/io/test_xlsx_table.py b/tests/io/test_xlsx_table.py
--- a/tests/io/test_xlsx_table.py
+++ b/tests/io/test_xlsx_table.py
@@ -131,4 +131,4 @@ def test_tables_none():
         .astype({"CategoryID": int}),
     }
     for key, value in expected.items():
-        assert_frame_equal(value, actual[key])
+        assert_frame_equal(value, actual[key], check_dtype=False)
diff --git a/tests/utils/test__select_column.py b/tests/utils/test__select_column.py
--- a/tests/utils/test__select_column.py
+++ b/tests/utils/test__select_column.py
@@ -115,7 +115,7 @@ def test_tuple(df_tuple):
 def test_strings(df1):
     """Test _select_column_names function on strings."""
     assert _select_column_names("id", df1) == ["id"]
-    assert _select_column_names("*type*", df1) == [
+    assert _select_column_names("*type*", df1).tolist() == [
         "type",
         "type1",
         "type2",
@@ -127,7 +127,7 @@ def test_strings_cat(df1):
     """Test output on categorical columns"""
     df1.columns = df1.columns.astype("category")
     assert _select_column_names("id", df1) == ["id"]
-    assert _select_column_names("*type*", df1) == [
+    assert _select_column_names("*type*", df1).tolist() == [
         "type",
         "type1",
         "type2",