Skip to content

Commit

Permalink
Muted invalid value warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ml31415 committed Sep 22, 2023
1 parent 9bf8c44 commit 985f230
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions numpy_groupies/aggregate_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,24 @@ def _any(group_idx, a, size, fill_value, dtype=None):
def _min(group_idx, a, size, fill_value, dtype=None):
dtype = minimum_dtype(fill_value, dtype or a.dtype)
dmax = maxval(fill_value, dtype)
ret = np.full(size, fill_value, dtype=dtype)
with np.errstate(invalid="ignore"):
ret = np.full(size, fill_value, dtype=dtype)
if fill_value != dmax:
ret[group_idx] = dmax # min starts from maximum
np.minimum.at(ret, group_idx, a)
with np.errstate(invalid="ignore"):
np.minimum.at(ret, group_idx, a)
return ret


def _max(group_idx, a, size, fill_value, dtype=None):
dtype = minimum_dtype(fill_value, dtype or a.dtype)
dmin = minval(fill_value, dtype)
ret = np.full(size, fill_value, dtype=dtype)
with np.errstate(invalid="ignore"):
ret = np.full(size, fill_value, dtype=dtype)
if fill_value != dmin:
ret[group_idx] = dmin # max starts from minimum
np.maximum.at(ret, group_idx, a)
with np.errstate(invalid="ignore"):
np.maximum.at(ret, group_idx, a)
return ret


Expand Down
3 changes: 2 additions & 1 deletion numpy_groupies/aggregate_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def _wrapper(group_idx, a, size, fill_value, func="sum", dtype=None, ddof=0, **k
ret = grouped.values[:, 0]
else:
ret = np.full(size, fill_value, dtype=dtype)
ret[grouped.index] = grouped.values[:, 0]
with np.errstate(invalid="ignore"):
ret[grouped.index] = grouped.values[:, 0]
return ret


Expand Down
3 changes: 2 additions & 1 deletion numpy_groupies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def minimum_dtype(x, dtype=np.bool_):

def check_type(x, dtype):
try:
converted = np.array(x).astype(dtype)
with np.errstate(invalid="ignore"):
converted = np.array(x).astype(dtype)
except (ValueError, OverflowError, RuntimeWarning):
return False
# False if some overflow has happened
Expand Down

0 comments on commit 985f230

Please sign in to comment.