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
56896c86
Commit
56896c86
authored
1 year ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
data: check for quantified data in get routines; minor refactoring
parent
9d5cd731
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!260
Masked array support
Pipeline
#188152
passed with stages
in 5 minutes and 10 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/finam/data/tools.py
+25
-23
25 additions, 23 deletions
src/finam/data/tools.py
with
25 additions
and
23 deletions
src/finam/data/tools.py
+
25
−
23
View file @
56896c86
...
@@ -61,7 +61,7 @@ def prepare(data, info, time_entries=1, force_copy=False, report_conversion=Fals
...
@@ -61,7 +61,7 @@ def prepare(data, info, time_entries=1, force_copy=False, report_conversion=Fals
"""
"""
units_converted
=
None
units_converted
=
None
units
=
info
.
units
units
=
info
.
units
if
is
instance
(
data
,
pint
.
Quantity
):
if
is
_quantified
(
data
):
if
not
compatible_units
(
data
.
units
,
units
):
if
not
compatible_units
(
data
.
units
,
units
):
raise
FinamDataError
(
raise
FinamDataError
(
f
"
Given data has incompatible units.
"
f
"
Given data has incompatible units.
"
...
@@ -73,6 +73,7 @@ def prepare(data, info, time_entries=1, force_copy=False, report_conversion=Fals
...
@@ -73,6 +73,7 @@ def prepare(data, info, time_entries=1, force_copy=False, report_conversion=Fals
elif
force_copy
:
elif
force_copy
:
data
=
data
.
copy
()
data
=
data
.
copy
()
else
:
else
:
# this covers masked arrays as well
if
isinstance
(
data
,
np
.
ndarray
):
if
isinstance
(
data
,
np
.
ndarray
):
if
force_copy
:
if
force_copy
:
data
=
np
.
copy
(
data
)
data
=
np
.
copy
(
data
)
...
@@ -199,24 +200,6 @@ def to_datetime(date):
...
@@ -199,24 +200,6 @@ def to_datetime(date):
return
datetime
.
datetime
.
utcfromtimestamp
(
timestamp
)
return
datetime
.
datetime
.
utcfromtimestamp
(
timestamp
)
def
get_magnitude
(
xdata
):
"""
Get magnitude of given data.
Parameters
----------
xdata : pint.Quantity
The given data array.
Returns
-------
numpy.ndarray
Magnitude of given data.
"""
check_quantified
(
xdata
,
"
get_magnitude
"
)
return
xdata
.
magnitude
def
strip_time
(
xdata
,
grid
):
def
strip_time
(
xdata
,
grid
):
"""
Returns a view of the data with the time dimension squeezed if there is only a single entry
"""
Returns a view of the data with the time dimension squeezed if there is only a single entry
...
@@ -247,6 +230,24 @@ def strip_time(xdata, grid):
...
@@ -247,6 +230,24 @@ def strip_time(xdata, grid):
return
xdata
return
xdata
def
get_magnitude
(
xdata
):
"""
Get magnitude of given data.
Parameters
----------
xdata : pint.Quantity
The given data array.
Returns
-------
numpy.ndarray
Magnitude of given data.
"""
check_quantified
(
xdata
,
"
get_magnitude
"
)
return
xdata
.
magnitude
def
get_units
(
xdata
):
def
get_units
(
xdata
):
"""
"""
Get units of the data.
Get units of the data.
...
@@ -261,6 +262,7 @@ def get_units(xdata):
...
@@ -261,6 +262,7 @@ def get_units(xdata):
pint.Unit
pint.Unit
Units of the data.
Units of the data.
"""
"""
check_quantified
(
xdata
,
"
get_units
"
)
return
xdata
.
units
return
xdata
.
units
...
@@ -278,6 +280,7 @@ def get_dimensionality(xdata):
...
@@ -278,6 +280,7 @@ def get_dimensionality(xdata):
pint.UnitsContainer
pint.UnitsContainer
Dimensionality of the data.
Dimensionality of the data.
"""
"""
check_quantified
(
xdata
,
"
get_dimensionality
"
)
return
xdata
.
dimensionality
return
xdata
.
dimensionality
...
@@ -341,11 +344,10 @@ def full_like(xdata, value):
...
@@ -341,11 +344,10 @@ def full_like(xdata, value):
with the data filled with fill_value.
with the data filled with fill_value.
Units will be taken from the input if present.
Units will be taken from the input if present.
"""
"""
d
=
np
.
full_like
(
xdata
,
value
)
d
ata
=
np
.
full_like
(
xdata
,
value
)
if
is_quantified
(
xdata
):
if
is_quantified
(
xdata
):
return
UNITS
.
Quantity
(
d
,
xdata
.
units
)
return
UNITS
.
Quantity
(
data
,
xdata
.
units
)
return
data
return
d
def
full
(
value
,
info
):
def
full
(
value
,
info
):
...
...
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