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
3
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
9d5cd731
Commit
9d5cd731
authored
1 year ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
data: add tools for masked arrays
parent
4b21735d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!260
Masked array support
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/finam/data/__init__.py
+8
-0
8 additions, 0 deletions
src/finam/data/__init__.py
src/finam/data/tools.py
+66
-0
66 additions, 0 deletions
src/finam/data/tools.py
with
74 additions
and
0 deletions
src/finam/data/__init__.py
+
8
−
0
View file @
9d5cd731
...
...
@@ -88,12 +88,15 @@ from .tools import (
assert_type
,
check
,
check_quantified
,
filled
,
full
,
full_like
,
get_dimensionality
,
get_magnitude
,
get_units
,
has_masked_values
,
has_time_axis
,
is_masked_array
,
is_quantified
,
prepare
,
quantify
,
...
...
@@ -141,3 +144,8 @@ __all__ += [
"
to_datetime
"
,
"
to_units
"
,
]
__all__
+=
[
"
is_masked_array
"
,
"
has_masked_values
"
,
"
filled
"
,
]
This diff is collapsed.
Click to expand it.
src/finam/data/tools.py
+
66
−
0
View file @
9d5cd731
...
...
@@ -433,6 +433,72 @@ def is_quantified(xdata):
return
isinstance
(
xdata
,
pint
.
Quantity
)
def
is_masked_array
(
xdata
):
"""
Check if data is a masked array.
Parameters
----------
xdata : Any
The given data array.
Returns
-------
bool
Whether the data is a MaskedArray.
"""
if
is_quantified
(
xdata
):
return
np
.
ma
.
isMaskedArray
(
xdata
.
magnitude
)
return
np
.
ma
.
isMaskedArray
(
xdata
)
def
has_masked_values
(
xdata
):
"""
Determine whether the data has masked values.
Parameters
----------
xdata : Any
The given data array.
Returns
-------
bool
Whether the data is a MaskedArray and has any masked values.
"""
if
is_quantified
(
xdata
):
return
np
.
ma
.
is_masked
(
xdata
.
magnitude
)
return
np
.
ma
.
is_masked
(
xdata
)
def
filled
(
xdata
,
fill_value
=
None
):
"""
Return a filled array if the data is masked.
Parameters
----------
xdata : :class:`pint.Quantity` or :class:`numpy.ndarray` or :class:`numpy.ma.MaskedArray`
The reference object input.
fill_value : array_like, optional
The value to use for invalid entries. Can be scalar or non-scalar.
If non-scalar, the resulting ndarray must be broadcastable over
input array. Default is None, in which case, the `fill_value`
attribute of the array is used instead.
Returns
-------
pint.Quantity or numpy.ndarray
New object with the same shape and type as other,
with the data filled with fill_value.
Units will be taken from the input if present.
"""
if
not
is_masked_array
(
xdata
):
return
xdata
if
is_quantified
(
xdata
):
return
UNITS
.
Quantity
(
xdata
.
magnitude
.
filled
(
fill_value
),
xdata
.
units
)
return
xdata
.
filled
(
fill_value
)
def
quantify
(
xdata
,
units
=
None
):
"""
Quantifies data.
...
...
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