Skip to content

Commit

Permalink
resolve numpy2 compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariana Barzinpour committed Feb 4, 2025
1 parent 2c3e275 commit e4347e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions eodatasets3/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def _init_yaml() -> YAML:
yaml.representer.add_representer(numpy.uint32, Representer.represent_int)
yaml.representer.add_representer(numpy.int64, Representer.represent_int)
yaml.representer.add_representer(numpy.uint64, Representer.represent_int)
yaml.representer.add_representer(numpy.float32, Representer.represent_float)
yaml.representer.add_representer(numpy.float64, Representer.represent_float)
# Representer.represent_float is currently incompatible with numpy2 floats
yaml.representer.add_representer(numpy.float32, _represent_float)
yaml.representer.add_representer(numpy.float64, _represent_float)

yaml.representer.add_representer(numpy.ndarray, Representer.represent_list)
yaml.representer.add_representer(numpy.datetime64, _represent_numpy_datetime)
Expand Down
5 changes: 4 additions & 1 deletion eodatasets3/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,10 @@ def numpy_value_fits_dtype(value, dtype):
if _is_nan(value):
return np.issubdtype(dtype, np.floating)
else:
return np.all(np.array([value], dtype=dtype) == [value])
try:
return np.all(np.array([value], dtype=dtype) == [value])
except Exception: # pylint: disable=broad-except
return False


@define
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@
"fiona",
"h5py",
"jsonschema>=4.18", # We want a Draft6Validator
"numpy>=1.15.4,<2.0",
"numpy>=1.15.4",
"pyproj",
"rasterio",
"ruamel.yaml",
"scipy",
"shapely",
"structlog",
"xarray",
"datacube>=1.9.0-rc4",
"datacube>=1.9.0",
"python-rapidjson",
"pystac>=1.8.4",
],
Expand Down

0 comments on commit e4347e3

Please sign in to comment.