#37545 REF: Categorical.is_dtype_equal -> categories_match_up_to_permutation

Merged jbrockmendel
Coverage Reach
core/arrays/sparse/array.py core/arrays/sparse/dtype.py core/arrays/sparse/accessor.py core/arrays/sparse/scipy_sparse.py core/arrays/sparse/__init__.py core/arrays/categorical.py core/arrays/datetimelike.py core/arrays/datetimes.py core/arrays/timedeltas.py core/arrays/interval.py core/arrays/period.py core/arrays/integer.py core/arrays/boolean.py core/arrays/floating.py core/arrays/base.py core/arrays/numpy_.py core/arrays/string_.py core/arrays/masked.py core/arrays/_mixins.py core/arrays/_arrow_utils.py core/arrays/_ranges.py core/arrays/__init__.py core/indexes/base.py core/indexes/multi.py core/indexes/interval.py core/indexes/datetimelike.py core/indexes/range.py core/indexes/datetimes.py core/indexes/period.py core/indexes/category.py core/indexes/numeric.py core/indexes/extension.py core/indexes/accessors.py core/indexes/api.py core/indexes/timedeltas.py core/indexes/frozen.py core/internals/blocks.py core/internals/managers.py core/internals/construction.py core/internals/concat.py core/internals/ops.py core/internals/__init__.py core/groupby/groupby.py core/groupby/generic.py core/groupby/ops.py core/groupby/grouper.py core/groupby/numba_.py core/groupby/base.py core/groupby/categorical.py core/groupby/__init__.py core/reshape/merge.py core/reshape/reshape.py core/reshape/pivot.py core/reshape/concat.py core/reshape/tile.py core/reshape/melt.py core/reshape/util.py core/reshape/api.py core/generic.py core/dtypes/cast.py core/dtypes/dtypes.py core/dtypes/common.py core/dtypes/missing.py core/dtypes/concat.py core/dtypes/base.py core/dtypes/inference.py core/dtypes/generic.py core/dtypes/api.py core/frame.py core/computation/expr.py core/computation/pytables.py core/computation/ops.py core/computation/expressions.py core/computation/eval.py core/computation/scope.py core/computation/align.py core/computation/engines.py core/computation/parsing.py core/computation/common.py core/computation/check.py core/computation/api.py core/window/rolling.py core/window/ewm.py core/window/indexers.py core/window/expanding.py core/window/common.py core/window/numba_.py core/window/__init__.py core/strings/accessor.py core/strings/object_array.py core/strings/base.py core/strings/__init__.py core/series.py core/indexing.py core/algorithms.py core/ops/array_ops.py core/ops/__init__.py core/ops/docstrings.py core/ops/missing.py core/ops/mask_ops.py core/ops/common.py core/ops/methods.py core/ops/roperator.py core/ops/invalid.py core/ops/dispatch.py core/nanops.py core/resample.py core/tools/datetimes.py core/tools/times.py core/tools/numeric.py core/tools/timedeltas.py core/base.py core/missing.py core/aggregation.py core/apply.py core/sorting.py core/common.py core/construction.py core/config_init.py core/util/hashing.py core/util/numba_.py core/indexers.py core/array_algos/masked_reductions.py core/array_algos/replace.py core/array_algos/transforms.py core/accessor.py core/arraylike.py core/flags.py core/api.py core/shared_docs.py core/index.py core/sparse/api.py io/formats/format.py io/formats/style.py io/formats/excel.py io/formats/html.py io/formats/latex.py io/formats/info.py io/formats/printing.py io/formats/csvs.py io/formats/string.py io/formats/css.py io/formats/console.py io/pytables.py io/excel/_base.py io/excel/_openpyxl.py io/excel/_odfreader.py io/excel/_odswriter.py io/excel/_xlsxwriter.py io/excel/_xlwt.py io/excel/_util.py io/excel/_xlrd.py io/excel/_pyxlsb.py io/sas/sas7bdat.py io/sas/sas_xport.py io/sas/sas_constants.py io/sas/sasreader.py io/json/_json.py io/json/_table_schema.py io/json/_normalize.py io/html.py io/clipboard/__init__.py io/common.py io/parquet.py io/date_converters.py io/feather_format.py io/gbq.py io/api.py io/spss.py io/orc.py io/clipboards.py plotting/_matplotlib/core.py plotting/_matplotlib/converter.py plotting/_matplotlib/misc.py plotting/_matplotlib/boxplot.py plotting/_matplotlib/tools.py plotting/_matplotlib/hist.py plotting/_matplotlib/timeseries.py plotting/_matplotlib/style.py plotting/_matplotlib/__init__.py plotting/_matplotlib/compat.py plotting/_core.py plotting/_misc.py _testing.py util/_decorators.py util/_validators.py util/_doctools.py util/_test_decorators.py util/_print_versions.py util/_depr_module.py util/_tester.py util/_exceptions.py util/testing.py tseries/frequencies.py tseries/holiday.py tseries/api.py tseries/offsets.py _config/config.py _config/localization.py _config/display.py _config/dates.py _config/__init__.py compat/numpy/function.py compat/numpy/__init__.py compat/pickle_compat.py compat/_optional.py compat/__init__.py compat/chainmap.py errors/__init__.py _libs/tslibs/__init__.py _libs/__init__.py api/extensions/__init__.py api/types/__init__.py api/indexers/__init__.py

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -296,7 +296,7 @@
Loading
296 296
        raise TypeError("dtype of categories must be the same")
297 297
298 298
    ordered = False
299 -
    if all(first.is_dtype_equal(other) for other in to_union[1:]):
299 +
    if all(first._categories_match_up_to_permutation(other) for other in to_union[1:]):
300 300
        # identical categories - fastpath
301 301
        categories = first.categories
302 302
        ordered = first.ordered

@@ -255,7 +255,7 @@
Loading
255 255
        """
256 256
        if is_categorical_dtype(other):
257 257
            other = extract_array(other)
258 -
            if not other.is_dtype_equal(self):
258 +
            if not other._categories_match_up_to_permutation(self):
259 259
                raise TypeError(
260 260
                    "categories must match existing categories when appending"
261 261
                )

@@ -1083,7 +1083,7 @@
Loading
1083 1083
            # if either left or right is a categorical
1084 1084
            # then the must match exactly in categories & ordered
1085 1085
            if lk_is_cat and rk_is_cat:
1086 -
                if lk.is_dtype_equal(rk):
1086 +
                if lk._categories_match_up_to_permutation(rk):
1087 1087
                    continue
1088 1088
1089 1089
            elif lk_is_cat or rk_is_cat:

@@ -78,7 +78,7 @@
Loading
78 78
            # the same (maybe up to ordering, depending on ordered)
79 79
80 80
            msg = "Categoricals can only be compared if 'categories' are the same."
81 -
            if not self.is_dtype_equal(other):
81 +
            if not self._categories_match_up_to_permutation(other):
82 82
                raise TypeError(msg)
83 83
84 84
            if not self.ordered and not self.categories.equals(other.categories):
@@ -1874,11 +1874,12 @@
Loading
1874 1874
1875 1875
        # require identical categories set
1876 1876
        if isinstance(value, Categorical):
1877 -
            if not is_dtype_equal(self, value):
1877 +
            if not is_dtype_equal(self.dtype, value.dtype):
1878 1878
                raise ValueError(
1879 1879
                    "Cannot set a Categorical with another, "
1880 1880
                    "without identical categories"
1881 1881
                )
1882 +
            # is_dtype_equal implies categories_match_up_to_permutation
1882 1883
            new_codes = self._validate_listlike(value)
1883 1884
            value = Categorical.from_codes(new_codes, dtype=self.dtype)
1884 1885
@@ -2112,7 +2113,7 @@
Loading
2112 2113
        """
2113 2114
        if not isinstance(other, Categorical):
2114 2115
            return False
2115 -
        elif self.is_dtype_equal(other):
2116 +
        elif self._categories_match_up_to_permutation(other):
2116 2117
            other_codes = self._validate_listlike(other)
2117 2118
            return np.array_equal(self._codes, other_codes)
2118 2119
        return False
@@ -2125,7 +2126,7 @@
Loading
2125 2126
2126 2127
    # ------------------------------------------------------------------
2127 2128
2128 -
    def is_dtype_equal(self, other):
2129 +
    def _categories_match_up_to_permutation(self, other: "Categorical") -> bool:
2129 2130
        """
2130 2131
        Returns True if categoricals are the same dtype
2131 2132
          same categories, and same ordered
@@ -2138,8 +2139,17 @@
Loading
2138 2139
        -------
2139 2140
        bool
2140 2141
        """
2142 +
        return hash(self.dtype) == hash(other.dtype)
2143 +
2144 +
    def is_dtype_equal(self, other) -> bool:
2145 +
        warn(
2146 +
            "Categorical.is_dtype_equal is deprecated and will be removed "
2147 +
            "in a future version",
2148 +
            FutureWarning,
2149 +
            stacklevel=2,
2150 +
        )
2141 2151
        try:
2142 -
            return hash(self.dtype) == hash(other.dtype)
2152 +
            return self._categories_match_up_to_permutation(other)
2143 2153
        except (AttributeError, TypeError):
2144 2154
            return False
2145 2155

Learn more Showing 2 files with coverage changes found.

Changes in pandas/io/gbq.py
-2
+2
Loading file...
Changes in pandas/core/frame.py
-2
+2
Loading file...
Files Coverage
pandas -0.01% 94.21%
Project Totals (214 files) 94.21%
Loading