Skip to content

Commit 07d04cc

Browse files
committed
CLN: assorted
1 parent 13f758c commit 07d04cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+100
-158
lines changed

pandas/_libs/tslibs/conversion.pyx

+7-7
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,20 @@ cpdef inline datetime localize_pydatetime(datetime dt, tzinfo tz):
648648

649649

650650
cdef tzinfo convert_timezone(
651-
tzinfo tz_in,
652-
tzinfo tz_out,
653-
bint found_naive,
654-
bint found_tz,
655-
bint utc_convert,
651+
tzinfo tz_in,
652+
tzinfo tz_out,
653+
bint found_naive,
654+
bint found_tz,
655+
bint utc_convert,
656656
):
657657
"""
658658
Validate that ``tz_in`` can be converted/localized to ``tz_out``.
659659
660660
Parameters
661661
----------
662-
tz_in : tzinfo
662+
tz_in : tzinfo or None
663663
Timezone info of element being processed.
664-
tz_out : tzinfo
664+
tz_out : tzinfo or None
665665
Timezone info of output.
666666
found_naive : bool
667667
Whether a timezone-naive element has been found so far.

pandas/_testing/asserters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def assert_interval_array_equal(
531531
def assert_period_array_equal(left, right, obj: str = "PeriodArray") -> None:
532532
_check_isinstance(left, right, PeriodArray)
533533

534-
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
534+
assert_numpy_array_equal(left._ndarray, right._ndarray, obj=f"{obj}._ndarray")
535535
assert_attr_equal("freq", left, right, obj=obj)
536536

537537

@@ -541,7 +541,7 @@ def assert_datetime_array_equal(
541541
__tracebackhide__ = True
542542
_check_isinstance(left, right, DatetimeArray)
543543

544-
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
544+
assert_numpy_array_equal(left._ndarray, right._ndarray, obj=f"{obj}._ndarray")
545545
if check_freq:
546546
assert_attr_equal("freq", left, right, obj=obj)
547547
assert_attr_equal("tz", left, right, obj=obj)
@@ -552,7 +552,7 @@ def assert_timedelta_array_equal(
552552
) -> None:
553553
__tracebackhide__ = True
554554
_check_isinstance(left, right, TimedeltaArray)
555-
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
555+
assert_numpy_array_equal(left._ndarray, right._ndarray, obj=f"{obj}._ndarray")
556556
if check_freq:
557557
assert_attr_equal("freq", left, right, obj=obj)
558558

pandas/core/arrays/base.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1646,13 +1646,11 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
16461646

16471647

16481648
class ExtensionArraySupportsAnyAll(ExtensionArray):
1649-
def any(self, *, skipna: bool = True) -> bool: # type: ignore[empty-body]
1650-
# error: Missing return statement
1651-
pass
1649+
def any(self, *, skipna: bool = True) -> bool:
1650+
raise AbstractMethodError(self)
16521651

1653-
def all(self, *, skipna: bool = True) -> bool: # type: ignore[empty-body]
1654-
# error: Missing return statement
1655-
pass
1652+
def all(self, *, skipna: bool = True) -> bool:
1653+
raise AbstractMethodError(self)
16561654

16571655

16581656
class ExtensionOpsMixin:

pandas/core/arrays/categorical.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Literal,
1212
Sequence,
1313
TypeVar,
14-
Union,
1514
cast,
1615
overload,
1716
)
@@ -511,7 +510,7 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
511510
result = self.copy() if copy else self
512511

513512
elif is_categorical_dtype(dtype):
514-
dtype = cast("Union[str, CategoricalDtype]", dtype)
513+
dtype = cast(CategoricalDtype, dtype)
515514

516515
# GH 10696/18593/18630
517516
dtype = self.dtype.update_dtype(dtype)

pandas/core/arrays/datetimelike.py

-7
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,6 @@ def _check_compatible_with(self, other: DTScalarOrNaT) -> None:
257257
"""
258258
raise AbstractMethodError(self)
259259

260-
# ------------------------------------------------------------------
261-
# NDArrayBackedExtensionArray compat
262-
263-
@cache_readonly
264-
def _data(self) -> np.ndarray:
265-
return self._ndarray
266-
267260
# ------------------------------------------------------------------
268261

269262
def _box_func(self, x):

pandas/core/dtypes/missing.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import pandas._libs.missing as libmissing
1919
from pandas._libs.tslibs import (
2020
NaT,
21-
Period,
2221
iNaT,
2322
)
2423

@@ -749,10 +748,8 @@ def isna_all(arr: ArrayLike) -> bool:
749748
if dtype.kind == "f" and isinstance(dtype, np.dtype):
750749
checker = nan_checker
751750

752-
elif (
753-
(isinstance(dtype, np.dtype) and dtype.kind in ["m", "M"])
754-
or isinstance(dtype, DatetimeTZDtype)
755-
or dtype.type is Period
751+
elif (isinstance(dtype, np.dtype) and dtype.kind in ["m", "M"]) or isinstance(
752+
dtype, (DatetimeTZDtype, PeriodDtype)
756753
):
757754
# error: Incompatible types in assignment (expression has type
758755
# "Callable[[Any], Any]", variable has type "ufunc")

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7475,7 +7475,7 @@ def _cmp_method(self, other, op):
74757475
return self._construct_result(new_data)
74767476

74777477
def _arith_method(self, other, op):
7478-
if ops.should_reindex_frame_op(self, other, op, 1, 1, None, None):
7478+
if ops.should_reindex_frame_op(self, other, op, 1, None, None):
74797479
return ops.frame_arith_method_with_reindex(self, other, op)
74807480

74817481
axis: Literal[1] = 1 # only relevant for Series other case

pandas/core/groupby/groupby.py

-2
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,6 @@ def array_func(values: ArrayLike) -> ArrayLike:
16471647

16481648
return result
16491649

1650-
# TypeError -> we may have an exception in trying to aggregate
1651-
# continue and exclude the block
16521650
new_mgr = data.grouped_reduce(array_func)
16531651

16541652
res = self._wrap_agged_manager(new_mgr)

pandas/core/indexes/multi.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,9 @@ def _set_levels(
841841

842842
self._reset_cache()
843843

844-
def set_levels(self, levels, *, level=None, verify_integrity: bool = True):
844+
def set_levels(
845+
self, levels, *, level=None, verify_integrity: bool = True
846+
) -> MultiIndex:
845847
"""
846848
Set new levels on MultiIndex. Defaults to returning new index.
847849
@@ -856,8 +858,7 @@ def set_levels(self, levels, *, level=None, verify_integrity: bool = True):
856858
857859
Returns
858860
-------
859-
new index (of same type and class...etc) or None
860-
The same type as the caller or None if ``inplace=True``.
861+
MultiIndex
861862
862863
Examples
863864
--------

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,6 @@ def external_values(values: ArrayLike) -> ArrayLike:
22912291
# NB: for datetime64tz this is different from np.asarray(values), since
22922292
# that returns an object-dtype ndarray of Timestamps.
22932293
# Avoid raising in .astype in casting from dt64tz to dt64
2294-
return values._data
2294+
return values._ndarray
22952295
else:
22962296
return values

pandas/core/ops/__init__.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def to_series(right):
317317

318318

319319
def should_reindex_frame_op(
320-
left: DataFrame, right, op, axis, default_axis, fill_value, level
320+
left: DataFrame, right, op, axis: int, fill_value, level
321321
) -> bool:
322322
"""
323323
Check if this is an operation between DataFrames that will need to reindex.
@@ -331,7 +331,7 @@ def should_reindex_frame_op(
331331
if not isinstance(right, ABCDataFrame):
332332
return False
333333

334-
if fill_value is None and level is None and axis is default_axis:
334+
if fill_value is None and level is None and axis == 1:
335335
# TODO: any other cases we should handle here?
336336

337337
# Intersection is always unique so we have to check the unique columns
@@ -416,26 +416,22 @@ def _maybe_align_series_as_frame(frame: DataFrame, series: Series, axis: AxisInt
416416

417417
def flex_arith_method_FRAME(op):
418418
op_name = op.__name__.strip("_")
419-
default_axis = "columns"
420419

421420
na_op = get_array_op(op)
422421
doc = make_flex_doc(op_name, "dataframe")
423422

424423
@Appender(doc)
425-
def f(self, other, axis=default_axis, level=None, fill_value=None):
424+
def f(self, other, axis: Axis = "columns", level=None, fill_value=None):
425+
axis = self._get_axis_number(axis) if axis is not None else 1
426426

427-
if should_reindex_frame_op(
428-
self, other, op, axis, default_axis, fill_value, level
429-
):
427+
if should_reindex_frame_op(self, other, op, axis, fill_value, level):
430428
return frame_arith_method_with_reindex(self, other, op)
431429

432430
if isinstance(other, ABCSeries) and fill_value is not None:
433431
# TODO: We could allow this in cases where we end up going
434432
# through the DataFrame path
435433
raise NotImplementedError(f"fill_value {fill_value} not supported.")
436434

437-
axis = self._get_axis_number(axis) if axis is not None else 1
438-
439435
other = maybe_prepare_scalar_for_op(other, self.shape)
440436
self, other = align_method_FRAME(self, other, axis, flex=True, level=level)
441437

@@ -461,14 +457,13 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
461457

462458
def flex_comp_method_FRAME(op):
463459
op_name = op.__name__.strip("_")
464-
default_axis = "columns" # because we are "flex"
465460

466461
doc = _flex_comp_doc_FRAME.format(
467462
op_name=op_name, desc=_op_descriptions[op_name]["desc"]
468463
)
469464

470465
@Appender(doc)
471-
def f(self, other, axis=default_axis, level=None):
466+
def f(self, other, axis: Axis = "columns", level=None):
472467
axis = self._get_axis_number(axis) if axis is not None else 1
473468

474469
self, other = align_method_FRAME(self, other, axis, flex=True, level=level)

pandas/tests/apply/test_invalid_arg.py

-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ def test_transform_wont_agg_series(string_series, func):
355355
@pytest.mark.parametrize(
356356
"op_wrapper", [lambda x: x, lambda x: [x], lambda x: {"A": x}, lambda x: {"A": [x]}]
357357
)
358-
@pytest.mark.filterwarnings("ignore:.*Select only valid:FutureWarning")
359358
def test_transform_reducer_raises(all_reductions, frame_or_series, op_wrapper):
360359
# GH 35964
361360
op = op_wrapper(all_reductions)

pandas/tests/arithmetic/test_datetime64.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ def test_dt64arr_addsub_object_dtype_2d():
24202420

24212421
assert isinstance(result, DatetimeArray)
24222422
assert result.freq is None
2423-
tm.assert_numpy_array_equal(result._data, expected._data)
2423+
tm.assert_numpy_array_equal(result._ndarray, expected._ndarray)
24242424

24252425
with tm.assert_produces_warning(PerformanceWarning):
24262426
# Case where we expect to get a TimedeltaArray back

pandas/tests/arrays/datetimes/test_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ def test_freq_infer_raises(self):
122122
def test_copy(self):
123123
data = np.array([1, 2, 3], dtype="M8[ns]")
124124
arr = DatetimeArray(data, copy=False)
125-
assert arr._data is data
125+
assert arr._ndarray is data
126126

127127
arr = DatetimeArray(data, copy=True)
128-
assert arr._data is not data
128+
assert arr._ndarray is not data
129129

130130

131131
class TestSequenceToDT64NS:

pandas/tests/arrays/period/test_astype.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def test_astype_copies():
4242
result = arr.astype(np.int64, copy=False)
4343

4444
# Add the `.base`, since we now use `.asi8` which returns a view.
45-
# We could maybe override it in PeriodArray to return ._data directly.
46-
assert result.base is arr._data
45+
# We could maybe override it in PeriodArray to return ._ndarray directly.
46+
assert result.base is arr._ndarray
4747

4848
result = arr.astype(np.int64, copy=True)
49-
assert result is not arr._data
50-
tm.assert_numpy_array_equal(result, arr._data.view("i8"))
49+
assert result is not arr._ndarray
50+
tm.assert_numpy_array_equal(result, arr._ndarray.view("i8"))
5151

5252

5353
def test_astype_categorical():

pandas/tests/arrays/test_datetimelike.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_unbox_scalar(self):
220220
data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9
221221
arr = self.array_cls(data, freq="D")
222222
result = arr._unbox_scalar(arr[0])
223-
expected = arr._data.dtype.type
223+
expected = arr._ndarray.dtype.type
224224
assert isinstance(result, expected)
225225

226226
result = arr._unbox_scalar(NaT)
@@ -350,13 +350,13 @@ def test_getitem_near_implementation_bounds(self):
350350

351351
def test_getitem_2d(self, arr1d):
352352
# 2d slicing on a 1D array
353-
expected = type(arr1d)(arr1d._data[:, np.newaxis], dtype=arr1d.dtype)
353+
expected = type(arr1d)(arr1d._ndarray[:, np.newaxis], dtype=arr1d.dtype)
354354
result = arr1d[:, np.newaxis]
355355
tm.assert_equal(result, expected)
356356

357357
# Lookup on a 2D array
358358
arr2d = expected
359-
expected = type(arr2d)(arr2d._data[:3, 0], dtype=arr2d.dtype)
359+
expected = type(arr2d)(arr2d._ndarray[:3, 0], dtype=arr2d.dtype)
360360
result = arr2d[:3, 0]
361361
tm.assert_equal(result, expected)
362362

@@ -366,7 +366,7 @@ def test_getitem_2d(self, arr1d):
366366
assert result == expected
367367

368368
def test_iter_2d(self, arr1d):
369-
data2d = arr1d._data[:3, np.newaxis]
369+
data2d = arr1d._ndarray[:3, np.newaxis]
370370
arr2d = type(arr1d)._simple_new(data2d, dtype=arr1d.dtype)
371371
result = list(arr2d)
372372
assert len(result) == 3
@@ -376,7 +376,7 @@ def test_iter_2d(self, arr1d):
376376
assert x.dtype == arr1d.dtype
377377

378378
def test_repr_2d(self, arr1d):
379-
data2d = arr1d._data[:3, np.newaxis]
379+
data2d = arr1d._ndarray[:3, np.newaxis]
380380
arr2d = type(arr1d)._simple_new(data2d, dtype=arr1d.dtype)
381381

382382
result = repr(arr2d)
@@ -632,7 +632,7 @@ def test_array_interface(self, datetime_index):
632632

633633
# default asarray gives the same underlying data (for tz naive)
634634
result = np.asarray(arr)
635-
expected = arr._data
635+
expected = arr._ndarray
636636
assert result is expected
637637
tm.assert_numpy_array_equal(result, expected)
638638
result = np.array(arr, copy=False)
@@ -641,7 +641,7 @@ def test_array_interface(self, datetime_index):
641641

642642
# specifying M8[ns] gives the same result as default
643643
result = np.asarray(arr, dtype="datetime64[ns]")
644-
expected = arr._data
644+
expected = arr._ndarray
645645
assert result is expected
646646
tm.assert_numpy_array_equal(result, expected)
647647
result = np.array(arr, dtype="datetime64[ns]", copy=False)
@@ -720,13 +720,13 @@ def test_array_i8_dtype(self, arr1d):
720720
assert result.base is None
721721

722722
def test_from_array_keeps_base(self):
723-
# Ensure that DatetimeArray._data.base isn't lost.
723+
# Ensure that DatetimeArray._ndarray.base isn't lost.
724724
arr = np.array(["2000-01-01", "2000-01-02"], dtype="M8[ns]")
725725
dta = DatetimeArray(arr)
726726

727-
assert dta._data is arr
727+
assert dta._ndarray is arr
728728
dta = DatetimeArray(arr[:0])
729-
assert dta._data.base is arr
729+
assert dta._ndarray.base is arr
730730

731731
def test_from_dti(self, arr1d):
732732
arr = arr1d
@@ -941,7 +941,7 @@ def test_array_interface(self, timedelta_index):
941941

942942
# default asarray gives the same underlying data
943943
result = np.asarray(arr)
944-
expected = arr._data
944+
expected = arr._ndarray
945945
assert result is expected
946946
tm.assert_numpy_array_equal(result, expected)
947947
result = np.array(arr, copy=False)
@@ -950,7 +950,7 @@ def test_array_interface(self, timedelta_index):
950950

951951
# specifying m8[ns] gives the same result as default
952952
result = np.asarray(arr, dtype="timedelta64[ns]")
953-
expected = arr._data
953+
expected = arr._ndarray
954954
assert result is expected
955955
tm.assert_numpy_array_equal(result, expected)
956956
result = np.array(arr, dtype="timedelta64[ns]", copy=False)

pandas/tests/arrays/test_datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def test_shift_fill_value(self):
659659
dti = pd.date_range("2016-01-01", periods=3)
660660

661661
dta = dti._data
662-
expected = DatetimeArray(np.roll(dta._data, 1))
662+
expected = DatetimeArray(np.roll(dta._ndarray, 1))
663663

664664
fv = dta[-1]
665665
for fill_value in [fv, fv.to_pydatetime(), fv.to_datetime64()]:

0 commit comments

Comments
 (0)