Skip to content

Commit

Permalink
Fixed Scalar astype() method to call ArrayReturn to force 0-d arrays to
Browse files Browse the repository at this point in the history
be converted to scalars.  This resolves a problem in masked arrays where
in-place OR failed because the first argument as a 0-d bool array instead
of a bool scalar.
  • Loading branch information
Jason McCampbell (Enthought, Inc) committed Mar 16, 2011
1 parent 4f5f4b5 commit b92fbb6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion numpy/NumpyDotNet/IArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IArray
object argmax(object axis = null, ndarray @out = null);
object argmin(object axis = null, ndarray @out = null);
object argsort(object axis = null, string kind = null, object order = null);
ndarray astype(IronPython.Runtime.CodeContext cntx, object dtype = null);
object astype(IronPython.Runtime.CodeContext cntx, object dtype = null);
ndarray byteswap(bool inplace = false);
object choose([ParamDictionary] IDictionary<object,object> kwargs, params object[] args);
object clip(object min = null, object max = null, ndarray @out = null);
Expand Down
5 changes: 3 additions & 2 deletions numpy/NumpyDotNet/Scalar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ public object argsort(object axis = null, string kind = null, object order = nul
return ToArray().argsort(axis, kind, order);
}

public ndarray astype(CodeContext cntx, object dtype = null) {
return ToArray().astype(cntx, dtype);
public object astype(CodeContext cntx, object dtype = null) {
object ret = ToArray().astype(cntx, dtype);
return (ret is ndarray) ? ndarray.ArrayReturn((ndarray)ret) : ret;
}

public object @base {
Expand Down
2 changes: 1 addition & 1 deletion numpy/NumpyDotNet/ndarray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ public object argsort(object axis = null, string kind = null, object order = nul
return ArrayReturn(ArgSort(iAxis, sortkind));
}

public ndarray astype(CodeContext cntx, object dtype = null) {
public object astype(CodeContext cntx, object dtype = null) {
dtype d = NpyDescr.DescrConverter(cntx, dtype);
if (d == this.Dtype) {
return this;
Expand Down
4 changes: 3 additions & 1 deletion numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ def _check_fill_value(fill_value, ndtype):
fill_value = np.array(_recursive_set_fill_value(fill_value, descr),
dtype=ndtype)
else:
if isinstance(fill_value, basestring) and (ndtype.char not in 'SV'):
# On IronPython fill_value is not derived from basestring because it's of ScalarUnicode
# type and multiple inheritance isn't supported.
if (isinstance(fill_value, basestring) or isinstance(fill_value, np.unicode_)) and (ndtype.char not in 'SV'):
fill_value = default_fill_value(ndtype)
else:
# In case we want to convert 1e+20 to int...
Expand Down
2 changes: 1 addition & 1 deletion numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ def test_fillvalue_conversion(self):
assert_equal(b['a']._data, a._data)
assert_equal(b['a'].fill_value, a.fill_value)


@dec.knownfailureif(True, "Multiple index values (arr[(1,3)]) are not supported")
def test_fillvalue(self):
"Yet more fun with the fill_value"
data = masked_array([1, 2, 3], fill_value= -999)
Expand Down

0 comments on commit b92fbb6

Please sign in to comment.