Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FINAM
finam
Commits
0d771720
Commit
0d771720
authored
2 years ago
by
Martin Lange
Browse files
Options
Downloads
Patches
Plain Diff
slightly optimize tool function `equivalent_units`
parent
2f8530f6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!222
Xarray optimizations
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
benchmarks/data/test_tools.py
+11
-2
11 additions, 2 deletions
benchmarks/data/test_tools.py
src/finam/data/tools.py
+4
-2
4 additions, 2 deletions
src/finam/data/tools.py
with
15 additions
and
4 deletions
benchmarks/data/test_tools.py
+
11
−
2
View file @
0d771720
...
...
@@ -226,11 +226,20 @@ class TestUnitsTools(unittest.TestCase):
_result
=
self
.
benchmark
(
is_quantified
,
xdata
=
xdata
)
@pytest.mark.benchmark
(
group
=
"
data-tools
"
)
def
test_equivalent_units
(
self
):
def
test_equivalent_units
_true
(
self
):
time
=
dt
.
datetime
(
2000
,
1
,
1
)
info
=
fm
.
Info
(
time
=
time
,
grid
=
fm
.
UniformGrid
((
2
,
1
)),
units
=
"
mm
"
)
xdata
=
full
(
0.0
,
"
test
"
,
info
,
time
)
_result
=
self
.
benchmark
(
equivalent_units
,
unit1
=
xdata
,
unit2
=
"
L/m^2
"
)
result
=
self
.
benchmark
(
equivalent_units
,
unit1
=
xdata
,
unit2
=
"
L/m^2
"
)
self
.
assertTrue
(
result
)
@pytest.mark.benchmark
(
group
=
"
data-tools
"
)
def
test_equivalent_units_False
(
self
):
time
=
dt
.
datetime
(
2000
,
1
,
1
)
info
=
fm
.
Info
(
time
=
time
,
grid
=
fm
.
UniformGrid
((
2
,
1
)),
units
=
"
mm
"
)
xdata
=
full
(
0.0
,
"
test
"
,
info
,
time
)
result
=
self
.
benchmark
(
equivalent_units
,
unit1
=
xdata
,
unit2
=
"
m
"
)
self
.
assertFalse
(
result
)
@pytest.mark.benchmark
(
group
=
"
data-tools
"
)
def
test_compatible_units
(
self
):
...
...
This diff is collapsed.
Click to expand it.
src/finam/data/tools.py
+
4
−
2
View file @
0d771720
...
...
@@ -686,8 +686,10 @@ def equivalent_units(unit1, unit2):
Unit equivalence.
"""
unit1
,
unit2
=
_get_pint_units
(
unit1
),
_get_pint_units
(
unit2
)
ratio
=
((
1
*
unit1
)
/
(
1
*
unit2
)).
to_base_units
()
return
ratio
.
dimensionless
and
np
.
isclose
(
ratio
.
magnitude
,
1
)
try
:
return
np
.
isclose
((
1.0
*
unit1
).
to
(
unit2
).
magnitude
,
1.0
)
except
pint
.
errors
.
DimensionalityError
:
return
False
def
assert_type
(
cls
,
slot
,
obj
,
types
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment