From 5252ebafd207c0fc2800232c28511d8d918d3670 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 5 Jan 2020 11:43:01 -0800 Subject: [PATCH] CLN: remove Index/Series._is_homogeneous_type --- pandas/core/base.py | 18 ------------- pandas/core/indexes/multi.py | 25 ------------------- .../indexing/multiindex/test_multiindex.py | 12 --------- pandas/tests/series/test_dtypes.py | 7 ------ 4 files changed, 62 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index d38dbec684f35..7d499181c6ed1 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -628,24 +628,6 @@ def transpose(self, *args, **kwargs): """, ) - @property - def _is_homogeneous_type(self) -> bool: - """ - Whether the object has a single dtype. - - By definition, Series and Index are always considered homogeneous. - A MultiIndex may or may not be homogeneous, depending on the - dtypes of the levels. - - See Also - -------- - DataFrame._is_homogeneous_type : Whether all the columns in a - DataFrame have the same dtype. - MultiIndex._is_homogeneous_type : Whether all the levels of a - MultiIndex have the same dtype. - """ - return True - @property def shape(self): """ diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 19f36e071fd0e..d9e68b64f526d 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -661,31 +661,6 @@ def array(self): "'MultiIndex.to_numpy()' to get a NumPy array of tuples." ) - @property - def _is_homogeneous_type(self) -> bool: - """ - Whether the levels of a MultiIndex all have the same dtype. - - This looks at the dtypes of the levels. - - See Also - -------- - Index._is_homogeneous_type : Whether the object has a single - dtype. - DataFrame._is_homogeneous_type : Whether all the columns in a - DataFrame have the same dtype. - - Examples - -------- - >>> MultiIndex.from_tuples([ - ... ('a', 'b'), ('a', 'c')])._is_homogeneous_type - True - >>> MultiIndex.from_tuples([ - ... ('a', 1), ('a', 2)])._is_homogeneous_type - False - """ - return len({x.dtype for x in self.levels}) <= 1 - def _set_levels( self, levels, level=None, copy=False, validate=True, verify_integrity=False ): diff --git a/pandas/tests/indexing/multiindex/test_multiindex.py b/pandas/tests/indexing/multiindex/test_multiindex.py index 3339cb5f3150d..8163de8588232 100644 --- a/pandas/tests/indexing/multiindex/test_multiindex.py +++ b/pandas/tests/indexing/multiindex/test_multiindex.py @@ -1,5 +1,4 @@ import numpy as np -import pytest import pandas._libs.index as _index from pandas.errors import PerformanceWarning @@ -47,17 +46,6 @@ def test_multiindex_contains_dropped(self): assert "a" in idx.levels[0] assert "a" not in idx - @pytest.mark.parametrize( - "data, expected", - [ - (MultiIndex.from_product([(), ()]), True), - (MultiIndex.from_product([(1, 2), (3, 4)]), True), - (MultiIndex.from_product([("a", "b"), (1, 2)]), False), - ], - ) - def test_multiindex_is_homogeneous_type(self, data, expected): - assert data._is_homogeneous_type is expected - def test_indexing_over_hashtable_size_cutoff(self): n = 10000 diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index 4bf2f1bd82eff..a57ec2ba05d54 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -465,13 +465,6 @@ def test_infer_objects_series(self): assert actual.dtype == "object" tm.assert_series_equal(actual, expected) - def test_is_homogeneous_type(self): - with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): - empty = Series() - assert empty._is_homogeneous_type - assert Series([1, 2])._is_homogeneous_type - assert Series(pd.Categorical([1, 2]))._is_homogeneous_type - @pytest.mark.parametrize( "data", [