Skip to content

Commit 0706d58

Browse files
jbrockmendelluckyvs1
authored andcommitted
CLN: share .values (pandas-dev#38531)
1 parent 5ed2067 commit 0706d58

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

pandas/_testing.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,9 @@ def _get_ilevel_values(index, level):
834834
# skip exact index checking when `check_categorical` is False
835835
if check_exact and check_categorical:
836836
if not left.equals(right):
837-
diff = np.sum((left.values != right.values).astype(int)) * 100.0 / len(left)
837+
diff = (
838+
np.sum((left._values != right._values).astype(int)) * 100.0 / len(left)
839+
)
838840
msg = f"{obj} values are different ({np.round(diff, 5)} %)"
839841
raise_assert_detail(obj, msg, left, right)
840842
else:

pandas/core/indexes/base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pandas._libs.lib import is_datetime_array, no_default
2828
from pandas._libs.tslibs import IncompatibleFrequency, OutOfBoundsDatetime, Timestamp
2929
from pandas._libs.tslibs.timezones import tz_compare
30-
from pandas._typing import AnyArrayLike, Dtype, DtypeObj, Label, Shape, final
30+
from pandas._typing import AnyArrayLike, ArrayLike, Dtype, DtypeObj, Label, Shape, final
3131
from pandas.compat.numpy import function as nv
3232
from pandas.errors import DuplicateLabelError, InvalidIndexError
3333
from pandas.util._decorators import Appender, cache_readonly, doc
@@ -1164,7 +1164,7 @@ def to_series(self, index=None, name=None):
11641164
if name is None:
11651165
name = self.name
11661166

1167-
return Series(self.values.copy(), index=index, name=name)
1167+
return Series(self._values.copy(), index=index, name=name)
11681168

11691169
def to_frame(self, index: bool = True, name=None):
11701170
"""
@@ -4036,7 +4036,7 @@ def _wrap_joined_index(
40364036
# Uncategorized Methods
40374037

40384038
@property
4039-
def values(self) -> np.ndarray:
4039+
def values(self) -> ArrayLike:
40404040
"""
40414041
Return an array representing the data in the Index.
40424042
@@ -4055,7 +4055,7 @@ def values(self) -> np.ndarray:
40554055
Index.array : Reference to the underlying data.
40564056
Index.to_numpy : A NumPy array representing the underlying data.
40574057
"""
4058-
return self._data.view(np.ndarray)
4058+
return self._data
40594059

40604060
@cache_readonly
40614061
@doc(IndexOpsMixin.array)
@@ -5318,7 +5318,7 @@ def _maybe_cast_slice_bound(self, label, side: str_t, kind):
53185318
# wish to have special treatment for floats/ints, e.g. Float64Index and
53195319
# datetimelike Indexes
53205320
# reject them, if index does not contain label
5321-
if (is_float(label) or is_integer(label)) and label not in self.values:
5321+
if (is_float(label) or is_integer(label)) and label not in self._values:
53225322
raise self._invalid_indexer("slice", label)
53235323

53245324
return label

pandas/core/indexes/category.py

-5
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,6 @@ def _format_with_header(self, header: List[str], na_rep: str = "NaN") -> List[st
357357
def inferred_type(self) -> str:
358358
return "categorical"
359359

360-
@property
361-
def values(self):
362-
""" return the underlying data, which is a Categorical """
363-
return self._data
364-
365360
@doc(Index.__contains__)
366361
def __contains__(self, key: Any) -> bool:
367362
# if key is a NaN, check if any NaN is in self.

pandas/core/indexes/interval.py

-7
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,6 @@ def __contains__(self, key: Any) -> bool:
348348
def _multiindex(self) -> MultiIndex:
349349
return MultiIndex.from_arrays([self.left, self.right], names=["left", "right"])
350350

351-
@cache_readonly
352-
def values(self) -> IntervalArray:
353-
"""
354-
Return the IntervalIndex's data as an IntervalArray.
355-
"""
356-
return self._data
357-
358351
def __array_wrap__(self, result, context=None):
359352
# we don't want the superclass implementation
360353
return result

0 commit comments

Comments
 (0)