Skip to content

Commit 12ae4d6

Browse files
committed
This solves the Numba issue; the Awkward one will need an Awkward fix (update ak.nan_to_num).
1 parent 33f2418 commit 12ae4d6

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/vector/_backends/numba_object.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,31 @@
5252
def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
5353
if isinstance(x, numba.types.Array):
5454

55-
def nan_to_num_impl(x, copy=True, nan=0.0, posinf=None, neginf=None):
56-
out = numpy.copy(x).reshape(-1) if copy else x.reshape(-1)
57-
for i in range(len(out)):
58-
if numpy.isnan(out[i]):
59-
out[i] = nan
60-
if posinf is not None and numpy.isinf(out[i]) and out[i] > 0:
61-
out[i] = posinf
62-
if neginf is not None and numpy.isinf(out[i]) and out[i] < 0:
63-
out[i] = neginf
64-
return out.reshape(x.shape)
55+
if isinstance(nan, numba.types.Array):
56+
57+
def nan_to_num_impl(x, copy=True, nan=0.0, posinf=None, neginf=None):
58+
out = numpy.copy(x).reshape(-1) if copy else x.reshape(-1)
59+
for i in range(len(out)):
60+
if numpy.isnan(out[i]):
61+
out[i] = nan[i]
62+
if posinf is not None and numpy.isinf(out[i]) and out[i] > 0:
63+
out[i] = posinf
64+
if neginf is not None and numpy.isinf(out[i]) and out[i] < 0:
65+
out[i] = neginf
66+
return out.reshape(x.shape)
67+
68+
else:
69+
70+
def nan_to_num_impl(x, copy=True, nan=0.0, posinf=None, neginf=None):
71+
out = numpy.copy(x).reshape(-1) if copy else x.reshape(-1)
72+
for i in range(len(out)):
73+
if numpy.isnan(out[i]):
74+
out[i] = nan
75+
if posinf is not None and numpy.isinf(out[i]) and out[i] > 0:
76+
out[i] = posinf
77+
if neginf is not None and numpy.isinf(out[i]) and out[i] < 0:
78+
out[i] = neginf
79+
return out.reshape(x.shape)
6580

6681
else:
6782

0 commit comments

Comments
 (0)