Exemplo n.º 1
0
 def test_refine_rename_nan_category(self):
     # Get explicit, because pandas botches the comparison:
     #
     # >>> self._test_refine_spec_apply(
     #     pd.DataFrame({'A': [np.nan]}, dtype='category'),
     #     'A', RefineSpec({'b': 'c'}),
     #     pd.DataFrame({'A': [np.nan]}, dtype='category')
     # )
     # Attribute "dtype" are different
     # [left]:  CategoricalDtype(categories=[], ordered=False)
     # [right]: CategoricalDtype(categories=[], ordered=False)
     spec = RefineSpec({"b": "c"})
     result = spec.apply(pd.DataFrame({"A": []}, dtype="category"), "A")
     self.assertEqual(0, len(result))
     self.assertEqual(0, len(result["A"].cat.categories))
Exemplo n.º 2
0
    def _test_refine_spec_apply(
        self,
        in_table: pd.DataFrame,
        column: str,
        spec: RefineSpec,
        expected_out: pd.DataFrame = pd.DataFrame(),
        expected_error: str = "",
    ) -> None:
        """Render and assert the output is as expected."""
        result = spec.apply(in_table, column)

        if not expected_out.empty and expected_error:
            table, error = result
            self.assertEqual(error, expected_error)
            assert_frame_equal(table, expected_out)
        elif expected_error:
            self.assertEqual(result, expected_error)
        else:
            assert_frame_equal(result, expected_out)