Skip to content

Commit 64c0eb9

Browse files
committed
Fix for replacing NaN values
1 parent f457429 commit 64c0eb9

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/numcodecs_replace/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def encode(self, buf: Buffer) -> Buffer:
153153
}
154154

155155
for k, v in replacements.items():
156-
a[a == k] = v
156+
if isinstance(k, int) or not np.isnan(k):
157+
a[a == k] = v
158+
else:
159+
a[np.isnan(a)] = v
157160

158161
return a # type: ignore
159162

tests/test_replace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_roundtrip():
8181
with pytest.warns(RuntimeWarning, match="empty slice"):
8282
check_roundtrip(np.zeros((0,)))
8383
check_roundtrip(np.arange(1000).reshape(10, 10, 10))
84+
check_roundtrip(np.array([4.2, -2.4, np.nan, -np.nan, 0.0, -0.0]))
8485
check_roundtrip(np.array([np.inf, -np.inf, np.nan, -np.nan, 0.0, -0.0]))
8586
check_roundtrip(
8687
np.array(

0 commit comments

Comments
 (0)