Skip to content

Commit 9d9e5b6

Browse files
committed
CLN: .value -> ._values outside of core/ (pandas-dev#32781)
1 parent a5a09d3 commit 9d9e5b6

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
lines changed

pandas/io/formats/format.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@
5858
)
5959
from pandas.core.dtypes.generic import (
6060
ABCDatetimeIndex,
61-
ABCIndexClass,
6261
ABCMultiIndex,
6362
ABCPeriodIndex,
64-
ABCSeries,
65-
ABCSparseArray,
6663
ABCTimedeltaIndex,
6764
)
6865
from pandas.core.dtypes.missing import isna, notna
@@ -71,6 +68,7 @@
7168
from pandas.core.arrays.timedeltas import TimedeltaArray
7269
from pandas.core.base import PandasObject
7370
import pandas.core.common as com
71+
from pandas.core.construction import extract_array
7472
from pandas.core.indexes.api import Index, ensure_index
7573
from pandas.core.indexes.datetimes import DatetimeIndex
7674
from pandas.core.indexes.timedeltas import TimedeltaIndex
@@ -1228,11 +1226,7 @@ def _format(x):
12281226
# object dtype
12291227
return str(formatter(x))
12301228

1231-
vals = self.values
1232-
if isinstance(vals, Index):
1233-
vals = vals._values
1234-
elif isinstance(vals, ABCSparseArray):
1235-
vals = vals.values
1229+
vals = extract_array(self.values, extract_numpy=True)
12361230

12371231
is_float_type = lib.map_infer(vals, is_float) & notna(vals)
12381232
leading_space = self.leading_space
@@ -1457,9 +1451,7 @@ def _format_strings(self) -> List[str]:
14571451

14581452
class ExtensionArrayFormatter(GenericArrayFormatter):
14591453
def _format_strings(self) -> List[str]:
1460-
values = self.values
1461-
if isinstance(values, (ABCIndexClass, ABCSeries)):
1462-
values = values._values
1454+
values = extract_array(self.values, extract_numpy=True)
14631455

14641456
formatter = values._formatter(boxed=True)
14651457

pandas/io/json/_json.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,9 @@ def _try_convert_to_date(self, data):
973973
# ignore numbers that are out of range
974974
if issubclass(new_data.dtype.type, np.number):
975975
in_range = (
976-
isna(new_data.values)
976+
isna(new_data._values)
977977
| (new_data > self.min_stamp)
978-
| (new_data.values == iNaT)
978+
| (new_data._values == iNaT)
979979
)
980980
if not in_range.all():
981981
return data, False

pandas/io/pytables.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str):
23822382
mask = isna(categories)
23832383
if mask.any():
23842384
categories = categories[~mask]
2385-
codes[codes != -1] -= mask.astype(int).cumsum().values
2385+
codes[codes != -1] -= mask.astype(int).cumsum()._values
23862386

23872387
converted = Categorical.from_codes(
23882388
codes, categories=categories, ordered=ordered
@@ -4826,7 +4826,9 @@ def _convert_string_array(data: np.ndarray, encoding: str, errors: str) -> np.nd
48264826
# encode if needed
48274827
if len(data):
48284828
data = (
4829-
Series(data.ravel()).str.encode(encoding, errors).values.reshape(data.shape)
4829+
Series(data.ravel())
4830+
.str.encode(encoding, errors)
4831+
._values.reshape(data.shape)
48304832
)
48314833

48324834
# create the sized dtype
@@ -4865,7 +4867,7 @@ def _unconvert_string_array(
48654867
dtype = f"U{itemsize}"
48664868

48674869
if isinstance(data[0], bytes):
4868-
data = Series(data).str.decode(encoding, errors=errors).values
4870+
data = Series(data).str.decode(encoding, errors=errors)._values
48694871
else:
48704872
data = data.astype(dtype, copy=False).astype(object, copy=False)
48714873

pandas/io/stata.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ def _datetime_to_stata_elapsed_vec(dates: Series, fmt: str) -> Series:
351351

352352
def parse_dates_safe(dates, delta=False, year=False, days=False):
353353
d = {}
354-
if is_datetime64_dtype(dates.values):
354+
if is_datetime64_dtype(dates.dtype):
355355
if delta:
356356
time_delta = dates - stata_epoch
357-
d["delta"] = time_delta.values.astype(np.int64) // 1000 # microseconds
357+
d["delta"] = time_delta._values.astype(np.int64) // 1000 # microseconds
358358
if days or year:
359359
# ignore since mypy reports that DatetimeIndex has no year/month
360360
date_index = DatetimeIndex(dates)
@@ -368,7 +368,7 @@ def parse_dates_safe(dates, delta=False, year=False, days=False):
368368

369369
elif infer_dtype(dates, skipna=False) == "datetime":
370370
if delta:
371-
delta = dates.values - stata_epoch
371+
delta = dates._values - stata_epoch
372372

373373
def f(x: datetime.timedelta) -> float:
374374
return US_PER_DAY * x.days + 1000000 * x.seconds + x.microseconds
@@ -377,8 +377,8 @@ def f(x: datetime.timedelta) -> float:
377377
d["delta"] = v(delta)
378378
if year:
379379
year_month = dates.apply(lambda x: 100 * x.year + x.month)
380-
d["year"] = year_month.values // 100
381-
d["month"] = year_month.values - d["year"] * 100
380+
d["year"] = year_month._values // 100
381+
d["month"] = year_month._values - d["year"] * 100
382382
if days:
383383

384384
def g(x: datetime.datetime) -> int:
@@ -1956,7 +1956,7 @@ def _dtype_to_stata_type(dtype: np.dtype, column: Series) -> int:
19561956
if dtype.type == np.object_: # try to coerce it to the biggest string
19571957
# not memory efficient, what else could we
19581958
# do?
1959-
itemsize = max_len_string_array(ensure_object(column.values))
1959+
itemsize = max_len_string_array(ensure_object(column._values))
19601960
return max(itemsize, 1)
19611961
elif dtype == np.float64:
19621962
return 255
@@ -1998,7 +1998,7 @@ def _dtype_to_default_stata_fmt(
19981998
if force_strl:
19991999
return "%9s"
20002000
if dtype.type == np.object_:
2001-
itemsize = max_len_string_array(ensure_object(column.values))
2001+
itemsize = max_len_string_array(ensure_object(column._values))
20022002
if itemsize > max_str_len:
20032003
if dta_version >= 117:
20042004
return "%9s"
@@ -2151,7 +2151,7 @@ def _prepare_categoricals(self, data: DataFrame) -> DataFrame:
21512151
"It is not possible to export "
21522152
"int64-based categorical data to Stata."
21532153
)
2154-
values = data[col].cat.codes.values.copy()
2154+
values = data[col].cat.codes._values.copy()
21552155

21562156
# Upcast if needed so that correct missing values can be set
21572157
if values.max() >= get_base_missing_value(dtype):
@@ -2384,7 +2384,7 @@ def _encode_strings(self) -> None:
23842384
encoded = self.data[col].str.encode(self._encoding)
23852385
# If larger than _max_string_length do nothing
23862386
if (
2387-
max_len_string_array(ensure_object(encoded.values))
2387+
max_len_string_array(ensure_object(encoded._values))
23882388
<= self._max_string_length
23892389
):
23902390
self.data[col] = encoded
@@ -2650,7 +2650,7 @@ def _dtype_to_stata_type_117(dtype: np.dtype, column: Series, force_strl: bool)
26502650
if dtype.type == np.object_: # try to coerce it to the biggest string
26512651
# not memory efficient, what else could we
26522652
# do?
2653-
itemsize = max_len_string_array(ensure_object(column.values))
2653+
itemsize = max_len_string_array(ensure_object(column._values))
26542654
itemsize = max(itemsize, 1)
26552655
if itemsize <= 2045:
26562656
return itemsize

pandas/plotting/_matplotlib/misc.py

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
260260

261261
import matplotlib.pyplot as plt
262262

263+
# TODO: is the failure mentioned below still relevant?
263264
# random.sample(ndarray, int) fails on python 3.3, sigh
264265
data = list(series.values)
265266
samplings = [random.sample(data, size) for _ in range(samples)]

pandas/tseries/frequencies.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def infer_freq(index, warn: bool = True) -> Optional[str]:
289289
raise TypeError(
290290
f"cannot infer freq from a non-convertible index type {type(index)}"
291291
)
292-
index = index.values
292+
index = index._values
293293

294294
if not isinstance(index, pd.DatetimeIndex):
295295
index = pd.DatetimeIndex(index)
@@ -305,13 +305,13 @@ class _FrequencyInferer:
305305

306306
def __init__(self, index, warn: bool = True):
307307
self.index = index
308-
self.values = index.asi8
308+
self.i8values = index.asi8
309309

310310
# This moves the values, which are implicitly in UTC, to the
311311
# the timezone so they are in local time
312312
if hasattr(index, "tz"):
313313
if index.tz is not None:
314-
self.values = tz_convert(self.values, UTC, index.tz)
314+
self.i8values = tz_convert(self.i8values, UTC, index.tz)
315315

316316
self.warn = warn
317317

@@ -324,10 +324,12 @@ def __init__(self, index, warn: bool = True):
324324

325325
@cache_readonly
326326
def deltas(self):
327-
return unique_deltas(self.values)
327+
return unique_deltas(self.i8values)
328328

329329
@cache_readonly
330330
def deltas_asi8(self):
331+
# NB: we cannot use self.i8values here because we may have converted
332+
# the tz in __init__
331333
return unique_deltas(self.index.asi8)
332334

333335
@cache_readonly
@@ -341,7 +343,7 @@ def is_unique_asi8(self) -> bool:
341343
def get_freq(self) -> Optional[str]:
342344
"""
343345
Find the appropriate frequency string to describe the inferred
344-
frequency of self.values
346+
frequency of self.i8values
345347
346348
Returns
347349
-------
@@ -393,11 +395,11 @@ def hour_deltas(self):
393395

394396
@cache_readonly
395397
def fields(self):
396-
return build_field_sarray(self.values)
398+
return build_field_sarray(self.i8values)
397399

398400
@cache_readonly
399401
def rep_stamp(self):
400-
return Timestamp(self.values[0])
402+
return Timestamp(self.i8values[0])
401403

402404
def month_position_check(self):
403405
return libresolution.month_position_check(self.fields, self.index.dayofweek)

pandas/util/_doctools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _insert_index(self, data):
126126
if col_nlevels > 1:
127127
col = data.columns._get_level_values(0)
128128
values = [
129-
data.columns._get_level_values(i).values for i in range(1, col_nlevels)
129+
data.columns._get_level_values(i)._values for i in range(1, col_nlevels)
130130
]
131131
col_df = pd.DataFrame(values)
132132
data.columns = col_df.columns

0 commit comments

Comments
 (0)