Skip to content

Commit

Permalink
allow numpy 2.0 and fix python 3.12 support
Browse files Browse the repository at this point in the history
* catch unit parse exception raise since py3.12
* numpy 2.0 deprec of np.prod
* unpin astropy, numpy; bump pint
  • Loading branch information
cbyrohl authored Aug 21, 2024
1 parent bae6a17 commit 8c76b8b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
14 changes: 4 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
numpy = [
{version = "^1.21", python = "<3.12"},
{version = "^1.26", python = ">=3.12"}
]
numpy = ">=1.21"
# need dask>2024.4.1 for py>=3.11.9 (https://github.com/dask/dask/pull/11035)
dask = [{extras = ["array", "dataframe", "distributed"], version = ">=2023", python = "<3.11.9"},
{extras = ["array", "dataframe", "distributed"], version = ">=2024.4.1", python = ">=3.11.9"}
]
distributed = ">=2023"
h5py = "^3.7.0"
zarr = "^v2.10.0"
astropy = "^5.0"
numba = [
{version = "^0.57", python = "<3.12"},
{version = "^0.59", python = ">=3.12"}
]
astropy = ">=5.0"
numba = ">=0.57"
pyyaml = ">=5.3.1"
jupyter = "^1.0.0"
tqdm = "^4.64.1"
pint = "^0.22"
pint = "^0.24"
requests = "^2.31.0"


Expand Down
2 changes: 1 addition & 1 deletion src/scida/customs/arepo/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ def map_group_operation(
# TODO: very messy and inefficient routine. improve some time.
# TODO: Set entry_bytes_out
nbytes_dtype_out = 4 # TODO: hardcode 4 byte output dtype as estimate for now
entry_nbytes_out = nbytes_dtype_out * np.product(shape)
entry_nbytes_out = nbytes_dtype_out * np.prod(shape)

# list_chunkedges refers to bounds of index intervals to be processed together
# if idxlist is specified, then these indices do not have to refer to group indices.
Expand Down
8 changes: 8 additions & 0 deletions src/scida/interfaces/mixins/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import contextlib
import logging
import tokenize
from enum import Enum
from typing import Optional, Union

Expand Down Expand Up @@ -55,6 +56,9 @@ def str_to_unit(
unit = None
try:
unit = ureg(unitstr)
except tokenize.TokenError as e: # cannot parse; raises exception since python 3.12
log.debug("Cannot parse unit string '%s'. Skipping." % unitstr)
raise e
except pint.errors.UndefinedUnitError as e:
log.debug(
"Cannot parse unit string '%s' from metadata description. Skipping."
Expand Down Expand Up @@ -470,6 +474,10 @@ def add_units(container: FieldContainer, basepath: str):
)
except pint.errors.UndefinedUnitError:
self._unitstates[path] = UnitState.parse_error
except (
tokenize.TokenError
): # cannot parse; raises exception since python 3.12
self._unitstates[path] = UnitState.parse_error
except ValueError as e:
if str(e) != "Could not find units.":
raise e
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simulation_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_simulation_tng50(testdatapath):
# Compare dark matter mass
cosmology: FlatLambdaCDM = snp.cosmology
ureg = snp.unitregistry
vol = np.product(snp.boxsize) / cosmology.h**3 * ureg.kpc**3
vol = np.prod(snp.boxsize) / cosmology.h**3 * ureg.kpc**3
dens = (cosmology.Om0 - cosmology.Ob0) * cosmology.critical_density0
dens = dens.value * ureg(dens.unit.to_string("ogip"))
boxmass = vol * dens
Expand Down

0 comments on commit 8c76b8b

Please sign in to comment.