Skip to content

CLN: Index._values docstring + Block.internal/external_values #31103

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 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
8 changes: 4 additions & 4 deletions pandas/core/arrays/sparse/scipy_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def _check_is_partition(parts, whole):


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

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

nonnull_labels = ss.dropna()

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

def _sparse_series_to_coo(ss, row_levels=(0,), column_levels=(1,), sort_labels=False):
"""
Convert a SparseSeries to a scipy.sparse.coo_matrix using index
Convert a sparse Series to a scipy.sparse.coo_matrix using index
levels row_levels, column_levels as the row and column
labels respectively. Returns the sparse_matrix, row and column labels.
"""
Expand Down
13 changes: 7 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3645,24 +3645,25 @@ def values(self):

@property
def _values(self) -> Union[ExtensionArray, ABCIndexClass, np.ndarray]:
# TODO(EA): remove index types as they become extension arrays
"""
The best array representation.

This is an ndarray, ExtensionArray, or Index subclass. This differs
from ``_ndarray_values``, which always returns an ndarray.
This is an ndarray or ExtensionArray. This differs from
``_ndarray_values``, which always returns an ndarray.

Both ``_values`` and ``_ndarray_values`` are consistent between
``Series`` and ``Index``.
``Series`` and ``Index`` (except for datetime64[ns], which returns
a DatetimeArray for _values on the Index, but ndarray[M8ns] on the
Series).

It may differ from the public '.values' method.

index | values | _values | _ndarray_values |
----------------- | --------------- | ------------- | --------------- |
Index | ndarray | ndarray | ndarray |
CategoricalIndex | Categorical | Categorical | ndarray[int] |
DatetimeIndex | ndarray[M8ns] | ndarray[M8ns] | ndarray[M8ns] |
DatetimeIndex[tz] | ndarray[M8ns] | DTI[tz] | ndarray[M8ns] |
DatetimeIndex | ndarray[M8ns] | DatetimeArray | ndarray[M8ns] |
DatetimeIndex[tz] | ndarray[M8ns] | DatetimeArray | ndarray[M8ns] |
PeriodIndex | ndarray[object] | PeriodArray | ndarray[int] |
IntervalIndex | IntervalArray | IntervalArray | ndarray[object] |

Expand Down
4 changes: 0 additions & 4 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ def values(self):
"""
return self._data

@cache_readonly
def _values(self):
return self._data

def __array_wrap__(self, result, context=None):
# we don't want the superclass implementation
return result
Expand Down
20 changes: 13 additions & 7 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,19 @@ def is_categorical_astype(self, dtype):

return False

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

def internal_values(self, dtype=None):
""" return an internal format, currently just the ndarray
this should be the pure internal API format
def internal_values(self):
"""
The array that Series._values returns (internal values).
"""
return self.values

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

def external_values(self, dtype=None):
def external_values(self):
return self.values.astype(object)


Expand Down Expand Up @@ -2482,7 +2488,7 @@ def to_native_types(self, slicer=None, na_rep=None, quoting=None, **kwargs):
)
return rvalues

def external_values(self, dtype=None):
def external_values(self):
return np.asarray(self.values.astype("timedelta64[ns]", copy=False))


Expand Down
2 changes: 2 additions & 0 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,9 +1531,11 @@ def get_dtypes(self):
return np.array([self._block.dtype])

def external_values(self):
"""The array that Series.values returns"""
return self._block.external_values()

def internal_values(self):
"""The array that Series._values returns"""
return self._block.internal_values()

def get_values(self):
Expand Down