-
Notifications
You must be signed in to change notification settings - Fork 49
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
Adds a currency dimension #273
Open
samgdotson
wants to merge
27
commits into
yt-project:main
Choose a base branch
from
samgdotson:currency-dimension
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e839674
adds `currency` to dimensions
samgdotson c5259ee
adds `dollars` and `cents` to lut
samgdotson 78d9a62
adds necessary conversions and look ups
samgdotson 84182ec
autoformatting
samgdotson 2d3647d
flake8 fix in unit_systems.py
samgdotson c9881e4
includes more common currencies
samgdotson 937e495
merge main
samgdotson 4ef3926
removes unused derived dimensions for currency
samgdotson 53b97c0
prevents conversion between different currencies
samgdotson 23ccda5
blocks conversion via convert_to_units
samgdotson 24d33b0
tests that currency conversion is blocked
samgdotson 5ca2a64
verifies that currencies have currency dimensions
samgdotson 3ccaffe
removes currency definition from unit systems
samgdotson bb6c1ad
allows conversion between cents and dollars
samgdotson 05b2b04
blackify
samgdotson 45f62b5
adds aliases for yuan
samgdotson de5aff2
removes duplicate aliases
samgdotson fb67e0d
adds currency usage to documentation
samgdotson 566adbc
Merge branch 'currency-dimension' of github.com:samgdotson/unyt into …
samgdotson 445dcd2
trim trailing whitespace
samgdotson 79d355a
reduces code repetition
samgdotson dcad25d
blackify
samgdotson fffc3bd
blackify properly
samgdotson 25ce76e
merge energy-units
samgdotson b29a1e2
Merge branch 'currency-dimension' of github.com:samgdotson/unyt into …
samgdotson 03e8116
fixes LUT
samgdotson 1ad6211
formatting problems
samgdotson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,9 @@ class UnitSystem: | |
luminous_intensity_unit : string or :class:`unyt.unit_object.Unit`, optional | ||
The base luminous intensity unit of this unit system. | ||
Defaults to "cd". | ||
currency_unit : string or :class:`unyt.unit_object.Unit`, optional | ||
The base currency unit for this unit system. | ||
Defaults to "$". | ||
registry : :class:`unyt.unit_registry.UnitRegistry` object | ||
The unit registry associated with this unit system. Only | ||
useful for defining unit systems based on code units. | ||
|
@@ -200,6 +203,7 @@ def __init__( | |
current_mks_unit="A", | ||
luminous_intensity_unit="cd", | ||
logarithmic_unit="Np", | ||
currency_unit="$", | ||
registry=None, | ||
): | ||
self.registry = registry | ||
|
@@ -213,6 +217,7 @@ def __init__( | |
(dimensions.current_mks, current_mks_unit), | ||
(dimensions.luminous_intensity, luminous_intensity_unit), | ||
(dimensions.logarithmic, logarithmic_unit), | ||
(dimensions.currency, currency_unit), | ||
] | ||
) | ||
for k, v in self.units_map.items(): | ||
|
@@ -246,6 +251,7 @@ def __init__( | |
"current_mks", | ||
"luminous_intensity", | ||
"logarithmic", | ||
"currency", | ||
] | ||
self.registry = registry | ||
self.base_units = self.units_map.copy() | ||
|
@@ -298,7 +304,9 @@ def has_current_mks(self): | |
|
||
|
||
#: The CGS unit system | ||
cgs_unit_system = UnitSystem("cgs", "cm", "g", "s", current_mks_unit=None) | ||
cgs_unit_system = UnitSystem( | ||
"cgs", "cm", "g", "s", currency_unit="$", current_mks_unit=None | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
cgs_unit_system["energy"] = "erg" | ||
cgs_unit_system["specific_energy"] = "erg/g" | ||
cgs_unit_system["pressure"] = "dyne/cm**2" | ||
|
@@ -309,7 +317,7 @@ def has_current_mks(self): | |
cgs_unit_system["power"] = "erg/s" | ||
|
||
#: The MKS unit system | ||
mks_unit_system = UnitSystem("mks", "m", "kg", "s") | ||
mks_unit_system = UnitSystem("mks", "m", "kg", "s", currency_unit="$") | ||
mks_unit_system["energy"] = "J" | ||
mks_unit_system["specific_energy"] = "J/kg" | ||
mks_unit_system["pressure"] = "Pa" | ||
|
@@ -326,7 +334,9 @@ def has_current_mks(self): | |
mks_unit_system["luminous_flux"] = "lm" | ||
|
||
#: The imperial unit system | ||
imperial_unit_system = UnitSystem("imperial", "ft", "lb", "s", temperature_unit="R") | ||
imperial_unit_system = UnitSystem( | ||
"imperial", "ft", "lb", "s", temperature_unit="R", currency_unit="$" | ||
) | ||
imperial_unit_system["force"] = "lbf" | ||
imperial_unit_system["energy"] = "ft*lbf" | ||
imperial_unit_system["pressure"] = "lbf/ft**2" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these derived dimensions need to be added with explicit aliases in this namespace unless they're going to be used elsewhere inside
unyt
.