Skip to content

pq.Quantity(3, 'min') raises String parsing error #243

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

Closed
twmr opened this issue Sep 26, 2024 · 1 comment
Closed

pq.Quantity(3, 'min') raises String parsing error #243

twmr opened this issue Sep 26, 2024 · 1 comment

Comments

@twmr
Copy link
Contributor

twmr commented Sep 26, 2024

I've just noticed that pq.Quantity(3, 'min') raises an exception caused by parsing the unit.

----> 1 pq.Quantity(3, 'min')

File ~/pixi-main/.pixi/envs/default/lib/python3.12/site-packages/quantities/quantity.py:131, in Quantity.__new__(cls, data, units, dtype, copy)
    128     return np.asanyarray(data, dtype=dtype).view(cls)
    130 ret = np.asarray(data, dtype=dtype).view(cls)
--> 131 ret._dimensionality.update(validate_dimensionality(units))
    132 return ret

File ~/pixi-main/.pixi/envs/default/lib/python3.12/site-packages/quantities/quantity.py:34, in validate_dimensionality(value)
     32 if isinstance(value, str):
     33     try:
---> 34         return unit_registry[value].dimensionality
     35     except (KeyError, UnicodeDecodeError):
     36         return unit_registry[str(value)].dimensionality

File ~/pixi-main/.pixi/envs/default/lib/python3.12/site-packages/quantities/registry.py:71, in UnitRegistry.__getitem__(self, label)
     68 if "%" in label: label = label.replace("%", "percent")
     69 if label.lower() == "in": label = "inch"
---> 71 return self.__registry[label]

File ~/pixi-main/.pixi/envs/default/lib/python3.12/site-packages/quantities/registry.py:28, in UnitRegistry.__Registry.__getitem__(self, string)
     26 for builtin in all_builtins:
     27     if builtin in string:
---> 28         raise RuntimeError(f"String parsing error for {string}. Enter a string accepted by quantities")
     30 try:
     31     return eval(string, self.__context)

RuntimeError: String parsing error for min. Enter a string accepted by quantities

It worked in the past (tested with numpy 1.22.4, quantities 0.14.1, python 3.10)

With numpy 1.26.4, quantities 0.16.0 and python 3.12 I get the above exception.

@apdavison
Copy link
Contributor

I think this should be fixed by #242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants