Skip to content

CLN: move away from .values, _ndarray_values #32419

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
Mar 4, 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
16 changes: 8 additions & 8 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ def _get_ilevel_values(index, level):
if isinstance(left, pd.PeriodIndex) or isinstance(right, pd.PeriodIndex):
assert_attr_equal("freq", left, right, obj=obj)
if isinstance(left, pd.IntervalIndex) or isinstance(right, pd.IntervalIndex):
assert_interval_array_equal(left.values, right.values)
assert_interval_array_equal(left._values, right._values)

if check_categorical:
if is_categorical_dtype(left) or is_categorical_dtype(right):
assert_categorical_equal(left.values, right.values, obj=f"{obj} category")
assert_categorical_equal(left._values, right._values, obj=f"{obj} category")


def assert_class_equal(left, right, exact: Union[bool, str] = True, obj="Input"):
Expand Down Expand Up @@ -883,7 +883,7 @@ def assert_interval_array_equal(left, right, exact="equiv", obj="IntervalArray")
def assert_period_array_equal(left, right, obj="PeriodArray"):
_check_isinstance(left, right, PeriodArray)

assert_numpy_array_equal(left._data, right._data, obj=f"{obj}.values")
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
assert_attr_equal("freq", left, right, obj=obj)


Expand Down Expand Up @@ -1170,10 +1170,10 @@ def assert_series_equal(

# datetimelike may have different objects (e.g. datetime.datetime
# vs Timestamp) but will compare equal
if not Index(left.values).equals(Index(right.values)):
if not Index(left._values).equals(Index(right._values)):
msg = (
f"[datetimelike_compat=True] {left.values} "
f"is not equal to {right.values}."
f"[datetimelike_compat=True] {left._values} "
f"is not equal to {right._values}."
)
raise AssertionError(msg)
else:
Expand Down Expand Up @@ -1212,8 +1212,8 @@ def assert_series_equal(
if check_categorical:
if is_categorical_dtype(left) or is_categorical_dtype(right):
assert_categorical_equal(
left.values,
right.values,
left._values,
right._values,
obj=f"{obj} category",
check_category_order=check_category_order,
)
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,11 @@ def try_timedelta(v):
from pandas import to_timedelta

try:
return to_timedelta(v)._ndarray_values.reshape(shape)
td_values = to_timedelta(v)
except ValueError:
return v.reshape(shape)
else:
return np.asarray(td_values).reshape(shape)

inferred_type = lib.infer_datetimelike_array(ensure_object(v))

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4582,7 +4582,7 @@ def drop_duplicates(
duplicated = self.duplicated(subset, keep=keep)

if inplace:
(inds,) = (-duplicated)._ndarray_values.nonzero()
(inds,) = np.asarray(-duplicated).nonzero()
new_data = self._data.take(inds)

if ignore_index:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@ def _update_indexer(idxr, indexer=indexer):
indexer = _update_indexer(indexers, indexer=indexer)
else:
# no matches we are done
return Int64Index([])._ndarray_values
return np.array([], dtype=np.int64)

elif com.is_null_slice(k):
# empty slice
Expand All @@ -3024,7 +3024,7 @@ def _update_indexer(idxr, indexer=indexer):

# empty indexer
if indexer is None:
return Int64Index([])._ndarray_values
return np.array([], dtype=np.int64)

indexer = self._reorder_indexer(seq, indexer)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def equals(self, other) -> bool:
other = self._constructor(other)
if not is_dtype_equal(self.dtype, other.dtype) or self.shape != other.shape:
return False
left, right = self._ndarray_values, other._ndarray_values
left, right = self._values, other._values
return ((left == right) | (self._isnan & other._isnan)).all()
except (TypeError, ValueError):
return False
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra
continue

if convert_missing: # Replacement follows Stata notation
missing_loc = np.nonzero(missing._ndarray_values)[0]
missing_loc = np.nonzero(np.asarray(missing))[0]
umissing, umissing_loc = np.unique(series[missing], return_inverse=True)
replacement = Series(series, dtype=np.object)
for j, um in enumerate(umissing):
Expand Down
6 changes: 3 additions & 3 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ def _convert_1d(values, units, axis):
if isinstance(values, valid_types) or is_integer(values) or is_float(values):
return get_datevalue(values, axis.freq)
elif isinstance(values, PeriodIndex):
return values.asfreq(axis.freq)._ndarray_values
return values.asfreq(axis.freq).asi8
elif isinstance(values, Index):
return values.map(lambda x: get_datevalue(x, axis.freq))
elif lib.infer_dtype(values, skipna=False) == "period":
# https://github.com/pandas-dev/pandas/issues/24304
# convert ndarray[period] -> PeriodIndex
return PeriodIndex(values, freq=axis.freq)._ndarray_values
return PeriodIndex(values, freq=axis.freq).asi8
elif isinstance(values, (list, tuple, np.ndarray, Index)):
return [get_datevalue(x, axis.freq) for x in values]
return values
Expand Down Expand Up @@ -607,7 +607,7 @@ def _daily_finder(vmin, vmax, freq):
info = np.zeros(
span, dtype=[("val", np.int64), ("maj", bool), ("min", bool), ("fmt", "|S20")]
)
info["val"][:] = dates_._ndarray_values
info["val"][:] = dates_.asi8
info["fmt"][:] = ""
info["maj"][[0, -1]] = True
# .. and set some shortcuts
Expand Down