Skip to content

CLN: pragma no cover, post-array_ufunc #44006

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
Oct 15, 2021
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
6 changes: 3 additions & 3 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1428,13 +1428,13 @@ def diff_2d(
# see https://github.com/cython/cython/issues/2646
if (out_t is float32_t
and not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
raise NotImplementedError
raise NotImplementedError # pragma: no cover
elif (out_t is float64_t
and (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
raise NotImplementedError
raise NotImplementedError # pragma: no cover
elif out_t is int64_t and diff_t is not int64_t:
# We only have out_t of int64_t if we have datetimelike
raise NotImplementedError
raise NotImplementedError # pragma: no cover
else:
# We put this inside an indented else block to avoid cython build
# warnings about unreachable code
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/arrays.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cdef class NDArrayBacked:
elif "_ndarray" in state:
data = state.pop("_ndarray")
else:
raise ValueError
raise ValueError # pragma: no cover
self._ndarray = data
self._dtype = state.pop("_dtype")

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

data, dtype = state[:2]
if isinstance(dtype, np.ndarray):
Expand All @@ -107,9 +107,9 @@ cdef class NDArrayBacked:
for key, val in state[2].items():
setattr(self, key, val)
else:
raise NotImplementedError(state)
raise NotImplementedError(state) # pragma: no cover
else:
raise NotImplementedError(state)
raise NotImplementedError(state) # pragma: no cover

def __len__(self) -> int:
return len(self._ndarray)
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ cdef class IndexEngine:
return algos.is_monotonic(values, timelike=False)

cdef _make_hash_table(self, Py_ssize_t n):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

cdef _check_type(self, object val):
hash(val)
Expand Down Expand Up @@ -607,7 +607,7 @@ cdef class BaseMultiIndexCodesEngine:
self._base.__init__(self, lab_ints)

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

def _extract_level_codes(self, target) -> np.ndarray:
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/indexing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cdef class NDFrameIndexerBase:
if ndim is None:
ndim = self._ndim = self.obj.ndim
if ndim > 2:
raise ValueError(
raise ValueError( # pragma: no cover
"NDFrameIndexer does not support NDFrame objects with ndim > 2"
)
return ndim
4 changes: 2 additions & 2 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ cpdef Py_ssize_t slice_len(slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX) except -
Py_ssize_t start, stop, step, length

if slc is None:
raise TypeError("slc must be slice")
raise TypeError("slc must be slice") # pragma: no cover

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

Expand All @@ -358,7 +358,7 @@ cdef (Py_ssize_t, Py_ssize_t, Py_ssize_t, Py_ssize_t) slice_get_indices_ex(
Py_ssize_t start, stop, step, length

if slc is None:
raise TypeError("slc should be a slice")
raise TypeError("slc should be a slice") # pragma: no cover

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Resolution(Enum):
elif self == Resolution.RESO_YR:
return FreqGroup.FR_ANN
else:
raise ValueError(self)
raise ValueError(self) # pragma: no cover

@property
def attrname(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ cdef class BaseOffset:
When the specific offset subclass does not have a vectorized
implementation.
"""
raise NotImplementedError(
raise NotImplementedError( # pragma: no cover
f"DateOffset subclass {type(self).__name__} "
"does not have a vectorized implementation"
)
Expand Down
12 changes: 12 additions & 0 deletions pandas/core/array_algos/take.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ def wrapper(
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
libalgos.take_1d_int64_int64, np.int64, np.int64, np.int64
),
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
libalgos.take_1d_int64_int64, np.int64, np.int64, np.int64
),
}

_take_2d_axis0_dict = {
Expand Down Expand Up @@ -394,6 +397,9 @@ def wrapper(
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
libalgos.take_2d_axis0_int64_int64, np.int64, np.int64, fill_wrap=np.int64
),
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
libalgos.take_2d_axis0_int64_int64, np.int64, np.int64, fill_wrap=np.int64
),
}

_take_2d_axis1_dict = {
Expand Down Expand Up @@ -423,6 +429,9 @@ def wrapper(
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
libalgos.take_2d_axis1_int64_int64, np.int64, np.int64, fill_wrap=np.int64
),
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
libalgos.take_2d_axis1_int64_int64, np.int64, np.int64, fill_wrap=np.int64
),
}

_take_2d_multi_dict = {
Expand Down Expand Up @@ -452,6 +461,9 @@ def wrapper(
("datetime64[ns]", "datetime64[ns]"): _view_wrapper(
libalgos.take_2d_multi_int64_int64, np.int64, np.int64, fill_wrap=np.int64
),
("timedelta64[ns]", "timedelta64[ns]"): _view_wrapper(
libalgos.take_2d_multi_int64_int64, np.int64, np.int64, fill_wrap=np.int64
),
}


Expand Down
42 changes: 0 additions & 42 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,54 +2057,12 @@ def empty(self) -> bool_t:
def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:
return np.asarray(self._values, dtype=dtype)

def __array_wrap__(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason this was removed?

(dask has failures that seem to be caused by this, eg https://github.com/dask/dask/runs/4823351165?check_suite_focus=true)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was under the impression this was superceded by array_ufunc. If not, feel free to reinstate (with test)

self,
result: np.ndarray,
context: tuple[Callable, tuple[Any, ...], int] | None = None,
):
"""
Gets called after a ufunc and other functions.

Parameters
----------
result: np.ndarray
The result of the ufunc or other function called on the NumPy array
returned by __array__
context: tuple of (func, tuple, int)
This parameter is returned by ufuncs as a 3-element tuple: (name of the
ufunc, arguments of the ufunc, domain of the ufunc), but is not set by
other numpy functions.q

Notes
-----
Series implements __array_ufunc_ so this not called for ufunc on Series.
"""
res = lib.item_from_zerodim(result)
if is_scalar(res):
# e.g. we get here with np.ptp(series)
# ptp also requires the item_from_zerodim
return res
d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
# error: Argument 1 to "NDFrame" has incompatible type "ndarray";
# expected "BlockManager"
return self._constructor(res, **d).__finalize__( # type: ignore[arg-type]
self, method="__array_wrap__"
)

@final
def __array_ufunc__(
self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any
):
return arraylike.array_ufunc(self, ufunc, method, *inputs, **kwargs)

# ideally we would define this to avoid the getattr checks, but
# is slower
# @property
# def __array_interface__(self):
# """ provide numpy array interface method """
# values = self.values
# return dict(typestr=values.dtype.str,shape=values.shape,data=values)

# ----------------------------------------------------------------------
# Picklability

Expand Down
12 changes: 4 additions & 8 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str_t, *inputs, **kwargs):

def __array_wrap__(self, result, context=None):
"""
Gets called after a ufunc and other functions.
Gets called after a ufunc and other functions e.g. np.split.
"""
result = lib.item_from_zerodim(result)
if is_bool_dtype(result) or lib.is_scalar(result) or np.ndim(result) > 1:
Expand Down Expand Up @@ -6166,14 +6166,10 @@ def get_slice_bound(
raise err

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