From dc60a224af02376ecaf1ee2cbbdfc34a037ef6ce Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Mar 2020 18:06:51 -0700 Subject: [PATCH] DEPR: Index.is_mixed --- doc/source/whatsnew/v1.1.0.rst | 1 + pandas/core/indexes/base.py | 8 +++++++- pandas/tests/indexes/test_base.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 692df075f25cb..bd265ac1e5cf6 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -209,6 +209,7 @@ Deprecations - Setting values with ``.loc`` using a positional slice is deprecated and will raise in a future version. Use ``.loc`` with labels or ``.iloc`` with positions instead (:issue:`31840`) - :meth:`DataFrame.to_dict` has deprecated accepting short names for ``orient`` in future versions (:issue:`32515`) - :meth:`Categorical.to_dense` is deprecated and will be removed in a future version, use ``np.asarray(cat)`` instead (:issue:`32639`) +- :meth:`Index.is_mixed` is deprecated and will be removed in a future version, check ``index.inferred_type`` directly instead (:issue:`32922`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 83064fe22eaff..3d20d904e6e70 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1955,6 +1955,12 @@ def is_mixed(self) -> bool: >>> idx.is_mixed() False """ + warnings.warn( + "Index.is_mixed is deprecated and will be removed in a future version. " + "Check index.inferred_type directly instead.", + FutureWarning, + stacklevel=2, + ) return self.inferred_type in ["mixed"] def holds_integer(self) -> bool: @@ -3131,7 +3137,7 @@ def is_int(v): # convert the slice to an indexer here # if we are mixed and have integers - if is_positional and self.is_mixed(): + if is_positional: try: # Validate start & stop if start is not None: diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 5bdbc18769ce5..940e33a3f561f 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1161,6 +1161,12 @@ def test_intersection_difference(self, indices, sort): diff = indices.difference(indices, sort=sort) tm.assert_index_equal(inter, diff) + def test_is_mixed_deprecated(self): + # GH#32922 + index = self.create_index() + with tm.assert_produces_warning(FutureWarning): + index.is_mixed() + @pytest.mark.parametrize( "index, expected", [