-
Notifications
You must be signed in to change notification settings - Fork 0
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
[enhancement] internationalisation #88
Comments
It probably makes sense to "play" with For example, here we see that a meter from unitregistry1 cannot be added to a meter from unitregistry2: import pint
>>> ureg = pint.UnitRegistry()
>>> ureg2 = pint.UnitRegistry()
>>> len1 = 1 * ureg.m
>>> len2 = 2 * ureg.m
>>> len1+len2
<Quantity(3, 'meter')>
>>> len3 = 3 * ureg2.m
>>> len1+len3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ruud.wijtvliet/python/portfolyo/.venv/lib/python3.11/site-packages/pint/quantity.py", line 1154, in __add__
return self._add_sub(other, operator.add)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ruud.wijtvliet/python/portfolyo/.venv/lib/python3.11/site-packages/pint/quantity.py", line 139, in wrapped
return f(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ruud.wijtvliet/python/portfolyo/.venv/lib/python3.11/site-packages/pint/quantity.py", line 1032, in _add_sub
if not self._check(other):
^^^^^^^^^^^^^^^^^^
File "/Users/ruud.wijtvliet/python/portfolyo/.venv/lib/python3.11/site-packages/pint/util.py", line 846, in _check
raise ValueError(
ValueError: Cannot operate with Quantity and Quantity of different registries. That would be the disadvantage of creating a unit registry for each And it's why it's preferred to use the same unitregistry for each |
Currently, all powers are converted to MW, all energies to MWh, all prices to Eur/MWh, and all revenues to Eur. In some locations, all timestamps are converted to the "Europe/Berlin" timezone.
This improvement will make the package more "universal".
Branch:
internationalisation
Some desired behaviour:
When creating a
PfLine
, in the__init__
function a conversion of the units is no longer done before storing thedf
attribute. So, if the data is provided inGWh
, it is stored asGWh
, not asMWh
(as is currently done). It is also not automatically printed in units ofMWh
. This will require some changes to the__repr__
function. Maybe one of the functions here may be used.The previous point applies everywhere, where currently a
.to_baseunits()
is called.When doing arithmatic that involves various units (e.g. adding a constant to a PfLine, or when adding 2 PfLines together), the unit of the left object is used for the resulting PfLine.
One difficulty is that we also need to specify various currencies, e.g. USD and JPY etc, in
unitdefinitions.txt
, while specifying that these units cannot be converted into one another. Is this something thatpint
can even handle? If yes, this is the preferred way, because we can use one unit registry for all commodities. This also means we can keep on using theportfolyo.Q_()
class to create a validQuantity
for use with anyPfLine
- those that have a commodity, and those that do not. (The only thing we still need to verify that a PfLine does not mix currencies - e.g. prices in Eur/MWh and revenue in USD.)If the previous point (various currencies) is a problem in
pint
when using one unit registry, we will need to create a unitregistry for each commodity. This is not preferred, because it means that PfLines can only be created when also specifying a commodity. And each commodity will likely have its ownpint.UnitRegistry
, which is a disadvantage, because addition etc is no longer possible. It's likely also impossible to use multiple unit registries withpint_pandas
.Tackle this issue after doing #89 and before doing #86
The text was updated successfully, but these errors were encountered: