Skip to content

Commit 797f23e

Browse files
authored
CLN: Assorted (pandas-dev#50433)
* CLN: Assorted * troubleshoot * troubleshoot * troubleshoot * restore * restore * troubleshoot * revert copy=False * troubleshoot * remove warning filter
1 parent 17583b3 commit 797f23e

File tree

14 files changed

+27
-48
lines changed

14 files changed

+27
-48
lines changed

pandas/_libs/intervaltree.pxi.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ cdef class IntervalTree(IntervalMixin):
121121
"""
122122
if self._na_count > 0:
123123
return False
124-
values = [self.right, self.left]
125124

126-
sort_order = np.lexsort(values)
125+
sort_order = self.left_sorter
127126
return is_monotonic(sort_order, False)[0]
128127

129128
def get_indexer(self, scalar_t[:] target) -> np.ndarray:

pandas/_libs/tslibs/offsets.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from typing import (
1212

1313
import numpy as np
1414

15+
from pandas._libs.tslibs.nattype import NaTType
1516
from pandas._typing import npt
1617

1718
from .timedeltas import Timedelta
@@ -51,6 +52,8 @@ class BaseOffset:
5152
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ...
5253
@overload
5354
def __radd__(self, other: _TimedeltaT) -> _TimedeltaT: ...
55+
@overload
56+
def __radd__(self, other: NaTType) -> NaTType: ...
5457
def __sub__(self: _BaseOffsetT, other: BaseOffset) -> _BaseOffsetT: ...
5558
@overload
5659
def __rsub__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...

pandas/_libs/tslibs/util.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ cdef inline bint is_integer_object(object obj) nogil:
8383

8484
cdef inline bint is_float_object(object obj) nogil:
8585
"""
86-
Cython equivalent of `isinstance(val, (float, np.complex_))`
86+
Cython equivalent of `isinstance(val, (float, np.float_))`
8787
8888
Parameters
8989
----------

pandas/core/accessor.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
from __future__ import annotations
88

9+
from typing import final
910
import warnings
1011

1112
from pandas.util._decorators import doc
@@ -16,6 +17,7 @@ class DirNamesMixin:
1617
_accessors: set[str] = set()
1718
_hidden_attrs: frozenset[str] = frozenset()
1819

20+
@final
1921
def _dir_deletions(self) -> set[str]:
2022
"""
2123
Delete unwanted __dir__ for this object.

pandas/core/arrays/datetimelike.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray):
189189
Shared Base/Mixin class for DatetimeArray, TimedeltaArray, PeriodArray
190190
191191
Assumes that __new__/__init__ defines:
192-
_data
192+
_ndarray
193193
_freq
194194
195195
and that the inheriting class has methods:
@@ -1418,9 +1418,8 @@ def __add__(self, other):
14181418
# as is_integer returns True for these
14191419
if not is_period_dtype(self.dtype):
14201420
raise integer_op_not_supported(self)
1421-
result = cast("PeriodArray", self)._addsub_int_array_or_scalar(
1422-
other * self.freq.n, operator.add
1423-
)
1421+
obj = cast("PeriodArray", self)
1422+
result = obj._addsub_int_array_or_scalar(other * obj.freq.n, operator.add)
14241423

14251424
# array-like others
14261425
elif is_timedelta64_dtype(other_dtype):
@@ -1435,9 +1434,8 @@ def __add__(self, other):
14351434
elif is_integer_dtype(other_dtype):
14361435
if not is_period_dtype(self.dtype):
14371436
raise integer_op_not_supported(self)
1438-
result = cast("PeriodArray", self)._addsub_int_array_or_scalar(
1439-
other * self.freq.n, operator.add
1440-
)
1437+
obj = cast("PeriodArray", self)
1438+
result = obj._addsub_int_array_or_scalar(other * obj.freq.n, operator.add)
14411439
else:
14421440
# Includes Categorical, other ExtensionArrays
14431441
# For PeriodDtype, if self is a TimedeltaArray and other is a
@@ -1477,9 +1475,8 @@ def __sub__(self, other):
14771475
# as is_integer returns True for these
14781476
if not is_period_dtype(self.dtype):
14791477
raise integer_op_not_supported(self)
1480-
result = cast("PeriodArray", self)._addsub_int_array_or_scalar(
1481-
other * self.freq.n, operator.sub
1482-
)
1478+
obj = cast("PeriodArray", self)
1479+
result = obj._addsub_int_array_or_scalar(other * obj.freq.n, operator.sub)
14831480

14841481
elif isinstance(other, Period):
14851482
result = self._sub_periodlike(other)
@@ -1500,9 +1497,8 @@ def __sub__(self, other):
15001497
elif is_integer_dtype(other_dtype):
15011498
if not is_period_dtype(self.dtype):
15021499
raise integer_op_not_supported(self)
1503-
result = cast("PeriodArray", self)._addsub_int_array_or_scalar(
1504-
other * self.freq.n, operator.sub
1505-
)
1500+
obj = cast("PeriodArray", self)
1501+
result = obj._addsub_int_array_or_scalar(other * obj.freq.n, operator.sub)
15061502
else:
15071503
# Includes ExtensionArrays, float_dtype
15081504
return NotImplemented

pandas/core/arrays/interval.py

+2
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ def argsort(
812812
ascending = nv.validate_argsort_with_ascending(ascending, (), kwargs)
813813

814814
if ascending and kind == "quicksort" and na_position == "last":
815+
# TODO: in an IntervalIndex we can re-use the cached
816+
# IntervalTree.left_sorter
815817
return np.lexsort((self.right, self.left))
816818

817819
# TODO: other cases we can use lexsort for? much more performant.

pandas/core/groupby/groupby.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class providing the base-class of operations.
3232
cast,
3333
final,
3434
)
35-
import warnings
3635

3736
import numpy as np
3837

@@ -2200,13 +2199,8 @@ def sem(self, ddof: int = 1, numeric_only: bool = False):
22002199
counts = self.count()
22012200
result_ilocs = result.columns.get_indexer_for(cols)
22022201
count_ilocs = counts.columns.get_indexer_for(cols)
2203-
with warnings.catch_warnings():
2204-
# TODO(2.0): once iloc[:, foo] = bar depecation is enforced,
2205-
# this catching will be unnecessary
2206-
warnings.filterwarnings(
2207-
"ignore", ".*will attempt to set the values inplace.*"
2208-
)
2209-
result.iloc[:, result_ilocs] /= np.sqrt(counts.iloc[:, count_ilocs])
2202+
2203+
result.iloc[:, result_ilocs] /= np.sqrt(counts.iloc[:, count_ilocs])
22102204
return result
22112205

22122206
@final

pandas/core/internals/array_manager.py

-2
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,6 @@ def column_setitem(
863863
864864
This is a method on the ArrayManager level, to avoid creating an
865865
intermediate Series at the DataFrame level (`s = df[loc]; s[idx] = value`)
866-
867-
868866
"""
869867
if not is_integer(loc):
870868
raise TypeError("The column index should be an integer")

pandas/core/internals/blocks.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def apply(self, func, **kwargs) -> list[Block]:
325325

326326
return self._split_op_result(result)
327327

328+
@final
328329
def reduce(self, func) -> list[Block]:
329330
# We will apply the function and reshape the result into a single-row
330331
# Block with the same mgr_locs; squeezing will be done at a higher level
@@ -1957,19 +1958,6 @@ class ObjectBlock(NumpyBlock):
19571958
__slots__ = ()
19581959
is_object = True
19591960

1960-
def reduce(self, func) -> list[Block]:
1961-
"""
1962-
For object-dtype, we operate column-wise.
1963-
"""
1964-
assert self.ndim == 2
1965-
1966-
res = func(self.values)
1967-
1968-
assert isinstance(res, np.ndarray)
1969-
assert res.ndim == 1
1970-
res = res.reshape(-1, 1)
1971-
return [self.make_block_same_class(res)]
1972-
19731961
@maybe_split
19741962
def convert(
19751963
self,
@@ -1980,7 +1968,9 @@ def convert(
19801968
attempt to cast any object types to better types return a copy of
19811969
the block (if copy = True) by definition we ARE an ObjectBlock!!!!!
19821970
"""
1983-
if self.dtype != object:
1971+
if self.dtype != _dtype_obj:
1972+
# GH#50067 this should be impossible in ObjectBlock, but until
1973+
# that is fixed, we short-circuit here.
19841974
return [self]
19851975

19861976
values = self.values

pandas/core/series.py

-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:
856856

857857
# coercion
858858
__float__ = _coerce_method(float)
859-
__long__ = _coerce_method(int)
860859
__int__ = _coerce_method(int)
861860

862861
# ----------------------------------------------------------------------

pandas/core/tools/datetimes.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,7 @@ def _convert_listlike_datetimes(
398398

399399
elif is_datetime64_ns_dtype(arg_dtype):
400400
if not isinstance(arg, (DatetimeArray, DatetimeIndex)):
401-
try:
402-
return DatetimeIndex(arg, tz=tz, name=name)
403-
except ValueError:
404-
pass
401+
return DatetimeIndex(arg, tz=tz, name=name)
405402
elif utc:
406403
# DatetimeArray, DatetimeIndex
407404
return arg.tz_localize("utc")

pandas/tests/arithmetic/test_timedelta64.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ def test_td64arr_floordiv_td64arr_with_nat(
17511751
expected = np.array([1.0, 1.0, np.nan], dtype=np.float64)
17521752
expected = tm.box_expected(expected, xbox)
17531753
if box is DataFrame and using_array_manager:
1754-
# INFO(ArrayManager) floorfiv returns integer, and ArrayManager
1754+
# INFO(ArrayManager) floordiv returns integer, and ArrayManager
17551755
# performs ops column-wise and thus preserves int64 dtype for
17561756
# columns without missing values
17571757
expected[[0, 1]] = expected[[0, 1]].astype("int64")

pandas/tests/indexes/test_base.py

-1
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,6 @@ def test_isin_nan_common_float64(self, nulls_fixture):
891891
"index",
892892
[
893893
Index(["qux", "baz", "foo", "bar"]),
894-
# float64 Index overrides isin, so must be checked separately
895894
NumericIndex([1.0, 2.0, 3.0, 4.0], dtype=np.float64),
896895
],
897896
)

pandas/tests/reshape/concat/test_concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def test_concat_retain_attrs(data):
745745
@td.skip_array_manager_invalid_test
746746
@pytest.mark.parametrize("df_dtype", ["float64", "int64", "datetime64[ns]"])
747747
@pytest.mark.parametrize("empty_dtype", [None, "float64", "object"])
748-
def test_concat_ignore_emtpy_object_float(empty_dtype, df_dtype):
748+
def test_concat_ignore_empty_object_float(empty_dtype, df_dtype):
749749
# https://github.com/pandas-dev/pandas/issues/45637
750750
df = DataFrame({"foo": [1, 2], "bar": [1, 2]}, dtype=df_dtype)
751751
empty = DataFrame(columns=["foo", "bar"], dtype=empty_dtype)

0 commit comments

Comments
 (0)