Skip to content

Commit

Permalink
Update NaN references for new NumPy 2. (#8)
Browse files Browse the repository at this point in the history
* Update NaN references for new NumPy 2.
* Bump dolomite-base version
  • Loading branch information
LTLA authored Oct 23, 2024
1 parent 7343f39 commit 6279e94
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ python_requires = >=3.8
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
dolomite-base>=0.2.0
dolomite-base>=0.3.0
delayedarray>=0.5.0
h5py
numpy
Expand Down
4 changes: 2 additions & 2 deletions src/dolomite_matrix/_optimize_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def optimize_integer_storage(x, buffer_size: int = 1e8) -> _OptimizedStoragePara
elif upper < 2**31 - 1: # Yes, this is deliberate, as integer storage maxes out at 32-bit signed integers.
return _OptimizedStorageParameters(type="i4", placeholder=2**31-1, non_zero=attr.non_zero)

return _OptimizedStorageParameters(type="f8", placeholder=numpy.NaN, non_zero=attr.non_zero)
return _OptimizedStorageParameters(type="f8", placeholder=numpy.nan, non_zero=attr.non_zero)

else:
# If it's infinite, that means that 'x' is of length zero, otherwise
Expand Down Expand Up @@ -497,7 +497,7 @@ def optimize_float_storage(x, buffer_size: int = 1e8) -> _OptimizedStorageParame

placeholder = None
if not attr.has_nan:
placeholder = numpy.NaN
placeholder = numpy.nan
elif not attr.has_positive_inf:
placeholder = numpy.inf
elif not attr.has_negative_inf:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_DelayedMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_DelayedMask_dense():


def test_DelayedMask_dense_NaN():
y = numpy.array([[1,2,numpy.NaN],[4,5,6]])
m = dm.DelayedMask(y, numpy.NaN)
y = numpy.array([[1,2,numpy.nan],[4,5,6]])
m = dm.DelayedMask(y, numpy.nan)
block = delayedarray.to_dense_array(m)
assert numpy.ma.is_masked(block)
assert numpy.ma.is_masked(block[0,2])
Expand Down
14 changes: 7 additions & 7 deletions tests/test_optimize_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_optimize_float_storage_dense():
assert opt.type == "f8"
assert opt.placeholder is None

y = numpy.array([numpy.NaN,2,3])
y = numpy.array([numpy.nan,2,3])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder is None
Expand Down Expand Up @@ -354,33 +354,33 @@ def test_optimize_float_storage_dense_MaskedArray():
assert opt.type == "f8"
assert numpy.isnan(opt.placeholder)

y = numpy.ma.MaskedArray([numpy.NaN,2,3], mask=[False, True, False])
y = numpy.ma.MaskedArray([numpy.nan,2,3], mask=[False, True, False])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder == numpy.inf

y = numpy.ma.MaskedArray([numpy.NaN,2,numpy.inf], mask=[False, True, False])
y = numpy.ma.MaskedArray([numpy.nan,2,numpy.inf], mask=[False, True, False])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder == -numpy.inf

fstats = numpy.finfo(numpy.float64)
y = numpy.ma.MaskedArray([numpy.NaN, 2, numpy.inf, -numpy.inf], mask=[False, True, False, False])
y = numpy.ma.MaskedArray([numpy.nan, 2, numpy.inf, -numpy.inf], mask=[False, True, False, False])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder == fstats.min

y = numpy.ma.MaskedArray([numpy.NaN, 2, numpy.inf, -numpy.inf, fstats.min], mask=[False, True, False, False, False])
y = numpy.ma.MaskedArray([numpy.nan, 2, numpy.inf, -numpy.inf, fstats.min], mask=[False, True, False, False, False])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder == fstats.max

y = numpy.ma.MaskedArray([numpy.NaN, 2, numpy.inf, -numpy.inf, fstats.min, fstats.max], mask=[False, True, False, False, False, False])
y = numpy.ma.MaskedArray([numpy.nan, 2, numpy.inf, -numpy.inf, fstats.min, fstats.max], mask=[False, True, False, False, False, False])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder == 0

y = numpy.ma.MaskedArray([numpy.NaN, 2, numpy.inf, -numpy.inf, fstats.min, fstats.max, 0], mask=[False, True, False, False, False, False, False])
y = numpy.ma.MaskedArray([numpy.nan, 2, numpy.inf, -numpy.inf, fstats.min, fstats.max, 0], mask=[False, True, False, False, False, False, False])
opt = optim.optimize_float_storage(y)
assert opt.type == "f8"
assert opt.placeholder == fstats.min / 2
Expand Down

0 comments on commit 6279e94

Please sign in to comment.