Skip to content
Snippets Groups Projects
Commit 92f671f6 authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

data.tools: move 'filled' to mask tools

parent 51d62c8d
No related branches found
No related tags found
1 merge request!286Add mask to Info object
......@@ -3,7 +3,6 @@
from .core import (
assert_type,
check,
filled,
full,
full_like,
has_time_axis,
......@@ -15,6 +14,7 @@ from .info import Info
from .mask import (
Mask,
check_data_covers_domain,
filled,
from_compressed,
has_masked_values,
is_masked_array,
......
......@@ -337,41 +337,6 @@ def _check_shape(shape, grid):
)
def filled(data, fill_value=None):
"""
Return input as an array with masked data replaced by a fill value.
This routine respects quantified and un-quantified data.
Parameters
----------
data : :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.
See also
--------
:func:`numpy.ma.filled`:
Numpy routine doing the same.
"""
if not is_masked_array(data):
return data
if is_quantified(data):
return UNITS.Quantity(data.magnitude.filled(fill_value), data.units)
return data.filled(fill_value)
def assert_type(cls, slot, obj, types):
"""Type assertion."""
for t in types:
......
......@@ -55,6 +55,41 @@ def has_masked_values(data):
return np.ma.is_masked(data)
def filled(data, fill_value=None):
"""
Return input as an array with masked data replaced by a fill value.
This routine respects quantified and un-quantified data.
Parameters
----------
data : :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.
See also
--------
:func:`numpy.ma.filled`:
Numpy routine doing the same.
"""
if not is_masked_array(data):
return data
if is_quantified(data):
return UNITS.Quantity(data.magnitude.filled(fill_value), data.units)
return data.filled(fill_value)
def to_masked(data, **kwargs):
"""
Return a masked version of the data.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment