Skip to content

CLN: remove Index/Series._is_homogeneous_type #30712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
25 changes: 0 additions & 25 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/indexing/multiindex/test_multiindex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

import pandas._libs.index as _index
from pandas.errors import PerformanceWarning
Expand Down Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down