Skip to content

Commit

Permalink
ENH: Allow keyword arguments in auto-converted ma functions.
Browse files Browse the repository at this point in the history
Fixes numpy#4582.
  • Loading branch information
abalkin committed Apr 4, 2014
1 parent 547765d commit 67afdda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions numpy/ma/core.py
Expand Up @@ -33,6 +33,7 @@
from numpy import array as narray
from numpy.lib.function_base import angle
from numpy.compat import getargspec, formatargspec, long, basestring
from inspect import getcallargs
from numpy import expand_dims as n_expand_dims

if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -7238,15 +7239,21 @@ def getdoc(self):
doc = sig + doc
return doc
#
def __call__(self, a, *args, **params):
def __call__(self, *args, **params):
# Find the common parameters to the call and the definition
_extras = self._extras
common_params = set(params).intersection(_extras)
# Drop the common parameters from the call
for p in common_params:
_extras[p] = params.pop(p)
# Get the result
result = self._func.__call__(a, *args, **params).view(MaskedArray)
try:
params = getcallargs(self._func, *args, **params)
except TypeError:
result = self._func.__call__(*args, **params)
else:
result = self._func(**params)
result = result.view(MaskedArray)
if "fill_value" in common_params:
result.fill_value = _extras.get("fill_value", None)
if "hardmask" in common_params:
Expand Down
6 changes: 6 additions & 0 deletions numpy/ma/tests/test_core.py
Expand Up @@ -3643,6 +3643,12 @@ def test_append_masked_array_along_axis():
assert_array_equal(result.mask, expected.mask)


def test_ctors_with_keyword_args():
x = np.ma.zeros(shape=2, dtype="f8")
y = np.zeros(2)
assert_array_equal(x.data, y)
assert_equal(x.dtype, y.dtype)

###############################################################################
if __name__ == "__main__":
run_module_suite()

0 comments on commit 67afdda

Please sign in to comment.