Skip to content

Commit a0c7a8a

Browse files
jorisvandenbosscheWillAyd
authored andcommitted
CLN: Index._values docstring + Block.internal/external_values (#31103)
1 parent fb0f96e commit a0c7a8a

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

pandas/core/arrays/sparse/scipy_sparse.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def _check_is_partition(parts, whole):
1717

1818

1919
def _to_ijv(ss, row_levels=(0,), column_levels=(1,), sort_labels=False):
20-
""" For arbitrary (MultiIndexed) SparseSeries return
20+
""" For arbitrary (MultiIndexed) sparse Series return
2121
(v, i, j, ilabels, jlabels) where (v, (i, j)) is suitable for
2222
passing to scipy.sparse.coo constructor. """
2323
# index and column levels must be a partition of the index
2424
_check_is_partition([row_levels, column_levels], range(ss.index.nlevels))
2525

26-
# from the SparseSeries: get the labels and data for non-null entries
27-
values = ss._data.internal_values()._valid_sp_values
26+
# from the sparse Series: get the labels and data for non-null entries
27+
values = ss.array._valid_sp_values
2828

2929
nonnull_labels = ss.dropna()
3030

@@ -85,7 +85,7 @@ def _get_index_subset_to_coord_dict(index, subset, sort_labels=False):
8585

8686
def _sparse_series_to_coo(ss, row_levels=(0,), column_levels=(1,), sort_labels=False):
8787
"""
88-
Convert a SparseSeries to a scipy.sparse.coo_matrix using index
88+
Convert a sparse Series to a scipy.sparse.coo_matrix using index
8989
levels row_levels, column_levels as the row and column
9090
labels respectively. Returns the sparse_matrix, row and column labels.
9191
"""

pandas/core/indexes/base.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3925,24 +3925,25 @@ def values(self):
39253925

39263926
@property
39273927
def _values(self) -> Union[ExtensionArray, ABCIndexClass, np.ndarray]:
3928-
# TODO(EA): remove index types as they become extension arrays
39293928
"""
39303929
The best array representation.
39313930
3932-
This is an ndarray, ExtensionArray, or Index subclass. This differs
3933-
from ``_ndarray_values``, which always returns an ndarray.
3931+
This is an ndarray or ExtensionArray. This differs from
3932+
``_ndarray_values``, which always returns an ndarray.
39343933
39353934
Both ``_values`` and ``_ndarray_values`` are consistent between
3936-
``Series`` and ``Index``.
3935+
``Series`` and ``Index`` (except for datetime64[ns], which returns
3936+
a DatetimeArray for _values on the Index, but ndarray[M8ns] on the
3937+
Series).
39373938
39383939
It may differ from the public '.values' method.
39393940
39403941
index | values | _values | _ndarray_values |
39413942
----------------- | --------------- | ------------- | --------------- |
39423943
Index | ndarray | ndarray | ndarray |
39433944
CategoricalIndex | Categorical | Categorical | ndarray[int] |
3944-
DatetimeIndex | ndarray[M8ns] | ndarray[M8ns] | ndarray[M8ns] |
3945-
DatetimeIndex[tz] | ndarray[M8ns] | DTI[tz] | ndarray[M8ns] |
3945+
DatetimeIndex | ndarray[M8ns] | DatetimeArray | ndarray[M8ns] |
3946+
DatetimeIndex[tz] | ndarray[M8ns] | DatetimeArray | ndarray[M8ns] |
39463947
PeriodIndex | ndarray[object] | PeriodArray | ndarray[int] |
39473948
IntervalIndex | IntervalArray | IntervalArray | ndarray[object] |
39483949

pandas/core/indexes/interval.py

-4
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ def values(self):
405405
"""
406406
return self._data
407407

408-
@cache_readonly
409-
def _values(self):
410-
return self._data
411-
412408
def __array_wrap__(self, result, context=None):
413409
# we don't want the superclass implementation
414410
return result

pandas/core/internals/blocks.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,19 @@ def is_categorical_astype(self, dtype):
192192

193193
return False
194194

195-
def external_values(self, dtype=None):
196-
""" return an outside world format, currently just the ndarray """
195+
def external_values(self):
196+
"""
197+
The array that Series.values returns (public attribute).
198+
This has some historical constraints, and is overridden in block
199+
subclasses to return the correct array (e.g. period returns
200+
object ndarray and datetimetz a datetime64[ns] ndarray instead of
201+
proper extension array).
202+
"""
197203
return self.values
198204

199-
def internal_values(self, dtype=None):
200-
""" return an internal format, currently just the ndarray
201-
this should be the pure internal API format
205+
def internal_values(self):
206+
"""
207+
The array that Series._values returns (internal values).
202208
"""
203209
return self.values
204210

@@ -1966,7 +1972,7 @@ class ObjectValuesExtensionBlock(ExtensionBlock):
19661972
Series[T].values is an ndarray of objects.
19671973
"""
19681974

1969-
def external_values(self, dtype=None):
1975+
def external_values(self):
19701976
return self.values.astype(object)
19711977

19721978

@@ -2482,7 +2488,7 @@ def to_native_types(self, slicer=None, na_rep=None, quoting=None, **kwargs):
24822488
)
24832489
return rvalues
24842490

2485-
def external_values(self, dtype=None):
2491+
def external_values(self):
24862492
return np.asarray(self.values.astype("timedelta64[ns]", copy=False))
24872493

24882494

pandas/core/internals/managers.py

+2
Original file line numberDiff line numberDiff line change
@@ -1531,9 +1531,11 @@ def get_dtypes(self):
15311531
return np.array([self._block.dtype])
15321532

15331533
def external_values(self):
1534+
"""The array that Series.values returns"""
15341535
return self._block.external_values()
15351536

15361537
def internal_values(self):
1538+
"""The array that Series._values returns"""
15371539
return self._block.internal_values()
15381540

15391541
def get_values(self):

0 commit comments

Comments
 (0)