Skip to content

CLN: share .values #38531

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 3 commits into from
Dec 17, 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
4 changes: 3 additions & 1 deletion pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,9 @@ def _get_ilevel_values(index, level):
# skip exact index checking when `check_categorical` is False
if check_exact and check_categorical:
if not left.equals(right):
diff = np.sum((left.values != right.values).astype(int)) * 100.0 / len(left)
diff = (
np.sum((left._values != right._values).astype(int)) * 100.0 / len(left)
)
msg = f"{obj} values are different ({np.round(diff, 5)} %)"
raise_assert_detail(obj, msg, left, right)
else:
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pandas._libs.lib import is_datetime_array, no_default
from pandas._libs.tslibs import IncompatibleFrequency, OutOfBoundsDatetime, Timestamp
from pandas._libs.tslibs.timezones import tz_compare
from pandas._typing import AnyArrayLike, Dtype, DtypeObj, Label, Shape, final
from pandas._typing import AnyArrayLike, ArrayLike, Dtype, DtypeObj, Label, Shape, final
from pandas.compat.numpy import function as nv
from pandas.errors import DuplicateLabelError, InvalidIndexError
from pandas.util._decorators import Appender, cache_readonly, doc
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def to_series(self, index=None, name=None):
if name is None:
name = self.name

return Series(self.values.copy(), index=index, name=name)
return Series(self._values.copy(), index=index, name=name)

def to_frame(self, index: bool = True, name=None):
"""
Expand Down Expand Up @@ -4036,7 +4036,7 @@ def _wrap_joined_index(
# Uncategorized Methods

@property
def values(self) -> np.ndarray:
def values(self) -> ArrayLike:
"""
Return an array representing the data in the Index.

Expand All @@ -4055,7 +4055,7 @@ def values(self) -> np.ndarray:
Index.array : Reference to the underlying data.
Index.to_numpy : A NumPy array representing the underlying data.
"""
return self._data.view(np.ndarray)
return self._data

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

return label
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,6 @@ def _format_with_header(self, header: List[str], na_rep: str = "NaN") -> List[st
def inferred_type(self) -> str:
return "categorical"

@property
def values(self):
""" return the underlying data, which is a Categorical """
return self._data

@doc(Index.__contains__)
def __contains__(self, key: Any) -> bool:
# if key is a NaN, check if any NaN is in self.
Expand Down
7 changes: 0 additions & 7 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,6 @@ def __contains__(self, key: Any) -> bool:
def _multiindex(self) -> MultiIndex:
return MultiIndex.from_arrays([self.left, self.right], names=["left", "right"])

@cache_readonly
def values(self) -> IntervalArray:
"""
Return the IntervalIndex's data as an IntervalArray.
"""
return self._data

def __array_wrap__(self, result, context=None):
# we don't want the superclass implementation
return result
Expand Down