Skip to content

Commit c30afb2

Browse files
authored
CLN: pragma no cover, post-array_ufunc (pandas-dev#44006)
1 parent 33a53f1 commit c30afb2

File tree

10 files changed

+30
-64
lines changed

10 files changed

+30
-64
lines changed

pandas/_libs/algos.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1428,13 +1428,13 @@ def diff_2d(
14281428
# see https://github.com/cython/cython/issues/2646
14291429
if (out_t is float32_t
14301430
and not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
1431-
raise NotImplementedError
1431+
raise NotImplementedError # pragma: no cover
14321432
elif (out_t is float64_t
14331433
and (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
1434-
raise NotImplementedError
1434+
raise NotImplementedError # pragma: no cover
14351435
elif out_t is int64_t and diff_t is not int64_t:
14361436
# We only have out_t of int64_t if we have datetimelike
1437-
raise NotImplementedError
1437+
raise NotImplementedError # pragma: no cover
14381438
else:
14391439
# We put this inside an indented else block to avoid cython build
14401440
# warnings about unreachable code

pandas/_libs/arrays.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ cdef class NDArrayBacked:
8484
elif "_ndarray" in state:
8585
data = state.pop("_ndarray")
8686
else:
87-
raise ValueError
87+
raise ValueError # pragma: no cover
8888
self._ndarray = data
8989
self._dtype = state.pop("_dtype")
9090

@@ -95,7 +95,7 @@ cdef class NDArrayBacked:
9595
if len(state) == 1 and isinstance(state[0], dict):
9696
self.__setstate__(state[0])
9797
return
98-
raise NotImplementedError(state)
98+
raise NotImplementedError(state) # pragma: no cover
9999

100100
data, dtype = state[:2]
101101
if isinstance(dtype, np.ndarray):
@@ -107,9 +107,9 @@ cdef class NDArrayBacked:
107107
for key, val in state[2].items():
108108
setattr(self, key, val)
109109
else:
110-
raise NotImplementedError(state)
110+
raise NotImplementedError(state) # pragma: no cover
111111
else:
112-
raise NotImplementedError(state)
112+
raise NotImplementedError(state) # pragma: no cover
113113

114114
def __len__(self) -> int:
115115
return len(self._ndarray)

pandas/_libs/index.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ cdef class IndexEngine:
264264
return algos.is_monotonic(values, timelike=False)
265265

266266
cdef _make_hash_table(self, Py_ssize_t n):
267-
raise NotImplementedError
267+
raise NotImplementedError # pragma: no cover
268268

269269
cdef _check_type(self, object val):
270270
hash(val)
@@ -607,7 +607,7 @@ cdef class BaseMultiIndexCodesEngine:
607607
self._base.__init__(self, lab_ints)
608608

609609
def _codes_to_ints(self, ndarray[uint64_t] codes) -> np.ndarray:
610-
raise NotImplementedError("Implemented by subclass")
610+
raise NotImplementedError("Implemented by subclass") # pragma: no cover
611611

612612
def _extract_level_codes(self, target) -> np.ndarray:
613613
"""

pandas/_libs/indexing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cdef class NDFrameIndexerBase:
1919
if ndim is None:
2020
ndim = self._ndim = self.obj.ndim
2121
if ndim > 2:
22-
raise ValueError(
22+
raise ValueError( # pragma: no cover
2323
"NDFrameIndexer does not support NDFrame objects with ndim > 2"
2424
)
2525
return ndim

pandas/_libs/internals.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ cpdef Py_ssize_t slice_len(slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX) except -
338338
Py_ssize_t start, stop, step, length
339339

340340
if slc is None:
341-
raise TypeError("slc must be slice")
341+
raise TypeError("slc must be slice") # pragma: no cover
342342

343343
PySlice_GetIndicesEx(slc, objlen, &start, &stop, &step, &length)
344344

@@ -358,7 +358,7 @@ cdef (Py_ssize_t, Py_ssize_t, Py_ssize_t, Py_ssize_t) slice_get_indices_ex(
358358
Py_ssize_t start, stop, step, length
359359

360360
if slc is None:
361-
raise TypeError("slc should be a slice")
361+
raise TypeError("slc should be a slice") # pragma: no cover
362362

363363
PySlice_GetIndicesEx(slc, objlen, &start, &stop, &step, &length)
364364

pandas/_libs/tslibs/dtypes.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Resolution(Enum):
205205
elif self == Resolution.RESO_YR:
206206
return FreqGroup.FR_ANN
207207
else:
208-
raise ValueError(self)
208+
raise ValueError(self) # pragma: no cover
209209

210210
@property
211211
def attrname(self) -> str:

pandas/_libs/tslibs/offsets.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ cdef class BaseOffset:
574574
When the specific offset subclass does not have a vectorized
575575
implementation.
576576
"""
577-
raise NotImplementedError(
577+
raise NotImplementedError( # pragma: no cover
578578
f"DateOffset subclass {type(self).__name__} "
579579
"does not have a vectorized implementation"
580580
)

pandas/core/array_algos/take.py

+12
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ def wrapper(
373373
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
374374
libalgos.take_1d_int64_int64, np.int64, np.int64, np.int64
375375
),
376+
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
377+
libalgos.take_1d_int64_int64, np.int64, np.int64, np.int64
378+
),
376379
}
377380

378381
_take_2d_axis0_dict = {
@@ -402,6 +405,9 @@ def wrapper(
402405
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
403406
libalgos.take_2d_axis0_int64_int64, np.int64, np.int64, fill_wrap=np.int64
404407
),
408+
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
409+
libalgos.take_2d_axis0_int64_int64, np.int64, np.int64, fill_wrap=np.int64
410+
),
405411
}
406412

407413
_take_2d_axis1_dict = {
@@ -431,6 +437,9 @@ def wrapper(
431437
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
432438
libalgos.take_2d_axis1_int64_int64, np.int64, np.int64, fill_wrap=np.int64
433439
),
440+
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
441+
libalgos.take_2d_axis1_int64_int64, np.int64, np.int64, fill_wrap=np.int64
442+
),
434443
}
435444

436445
_take_2d_multi_dict = {
@@ -460,6 +469,9 @@ def wrapper(
460469
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
461470
libalgos.take_2d_multi_int64_int64, np.int64, np.int64, fill_wrap=np.int64
462471
),
472+
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
473+
libalgos.take_2d_multi_int64_int64, np.int64, np.int64, fill_wrap=np.int64
474+
),
463475
}
464476

465477

pandas/core/generic.py

-42
Original file line numberDiff line numberDiff line change
@@ -2057,54 +2057,12 @@ def empty(self) -> bool_t:
20572057
def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:
20582058
return np.asarray(self._values, dtype=dtype)
20592059

2060-
def __array_wrap__(
2061-
self,
2062-
result: np.ndarray,
2063-
context: tuple[Callable, tuple[Any, ...], int] | None = None,
2064-
):
2065-
"""
2066-
Gets called after a ufunc and other functions.
2067-
2068-
Parameters
2069-
----------
2070-
result: np.ndarray
2071-
The result of the ufunc or other function called on the NumPy array
2072-
returned by __array__
2073-
context: tuple of (func, tuple, int)
2074-
This parameter is returned by ufuncs as a 3-element tuple: (name of the
2075-
ufunc, arguments of the ufunc, domain of the ufunc), but is not set by
2076-
other numpy functions.q
2077-
2078-
Notes
2079-
-----
2080-
Series implements __array_ufunc_ so this not called for ufunc on Series.
2081-
"""
2082-
res = lib.item_from_zerodim(result)
2083-
if is_scalar(res):
2084-
# e.g. we get here with np.ptp(series)
2085-
# ptp also requires the item_from_zerodim
2086-
return res
2087-
d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
2088-
# error: Argument 1 to "NDFrame" has incompatible type "ndarray";
2089-
# expected "BlockManager"
2090-
return self._constructor(res, **d).__finalize__( # type: ignore[arg-type]
2091-
self, method="__array_wrap__"
2092-
)
2093-
20942060
@final
20952061
def __array_ufunc__(
20962062
self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any
20972063
):
20982064
return arraylike.array_ufunc(self, ufunc, method, *inputs, **kwargs)
20992065

2100-
# ideally we would define this to avoid the getattr checks, but
2101-
# is slower
2102-
# @property
2103-
# def __array_interface__(self):
2104-
# """ provide numpy array interface method """
2105-
# values = self.values
2106-
# return dict(typestr=values.dtype.str,shape=values.shape,data=values)
2107-
21082066
# ----------------------------------------------------------------------
21092067
# Picklability
21102068

pandas/core/indexes/base.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str_t, *inputs, **kwargs):
883883

884884
def __array_wrap__(self, result, context=None):
885885
"""
886-
Gets called after a ufunc and other functions.
886+
Gets called after a ufunc and other functions e.g. np.split.
887887
"""
888888
result = lib.item_from_zerodim(result)
889889
if is_bool_dtype(result) or lib.is_scalar(result) or np.ndim(result) > 1:
@@ -6182,14 +6182,10 @@ def get_slice_bound(
61826182
raise err
61836183

61846184
if isinstance(slc, np.ndarray):
6185-
# get_loc may return a boolean array or an array of indices, which
6185+
# get_loc may return a boolean array, which
61866186
# is OK as long as they are representable by a slice.
6187-
if is_bool_dtype(slc):
6188-
slc = lib.maybe_booleans_to_slice(slc.view("u1"))
6189-
else:
6190-
slc = lib.maybe_indices_to_slice(
6191-
slc.astype(np.intp, copy=False), len(self)
6192-
)
6187+
assert is_bool_dtype(slc.dtype)
6188+
slc = lib.maybe_booleans_to_slice(slc.view("u1"))
61936189
if isinstance(slc, np.ndarray):
61946190
raise KeyError(
61956191
f"Cannot get {side} slice bound for non-unique "

0 commit comments

Comments
 (0)