Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NaN references for new NumPy 2. #8

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading