Skip to content

Commit 9ca9b06

Browse files
jbrockmendelNico Cernek
authored and
Nico Cernek
committed
CLN: Exception in nanops (pandas-dev#28648)
1 parent be3a624 commit 9ca9b06

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

pandas/core/nanops.py

+17-23
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,21 @@ def f(values, axis=None, skipna=True, **kwds):
9797
for k, v in self.kwargs.items():
9898
if k not in kwds:
9999
kwds[k] = v
100-
try:
101-
if values.size == 0 and kwds.get("min_count") is None:
102-
# We are empty, returning NA for our type
103-
# Only applies for the default `min_count` of None
104-
# since that affects how empty arrays are handled.
105-
# TODO(GH-18976) update all the nanops methods to
106-
# correctly handle empty inputs and remove this check.
107-
# It *may* just be `var`
108-
return _na_for_min_count(values, axis)
109-
110-
if _USE_BOTTLENECK and skipna and _bn_ok_dtype(values.dtype, bn_name):
100+
101+
if values.size == 0 and kwds.get("min_count") is None:
102+
# We are empty, returning NA for our type
103+
# Only applies for the default `min_count` of None
104+
# since that affects how empty arrays are handled.
105+
# TODO(GH-18976) update all the nanops methods to
106+
# correctly handle empty inputs and remove this check.
107+
# It *may* just be `var`
108+
return _na_for_min_count(values, axis)
109+
110+
if _USE_BOTTLENECK and skipna and _bn_ok_dtype(values.dtype, bn_name):
111+
if kwds.get("mask", None) is None:
112+
# `mask` is not recognised by bottleneck, would raise
113+
# TypeError if called
114+
kwds.pop("mask", None)
111115
result = bn_func(values, axis=axis, **kwds)
112116

113117
# prefer to treat inf/-inf as NA, but must compute the func
@@ -116,18 +120,8 @@ def f(values, axis=None, skipna=True, **kwds):
116120
result = alt(values, axis=axis, skipna=skipna, **kwds)
117121
else:
118122
result = alt(values, axis=axis, skipna=skipna, **kwds)
119-
except Exception:
120-
try:
121-
result = alt(values, axis=axis, skipna=skipna, **kwds)
122-
except ValueError as e:
123-
# we want to transform an object array
124-
# ValueError message to the more typical TypeError
125-
# e.g. this is normally a disallowed function on
126-
# object arrays that contain strings
127-
128-
if is_object_dtype(values):
129-
raise TypeError(e)
130-
raise
123+
else:
124+
result = alt(values, axis=axis, skipna=skipna, **kwds)
131125

132126
return result
133127

0 commit comments

Comments
 (0)