Changeset 8094
- Timestamp:
- 02/08/10 00:21:33 (5 weeks ago)
- Location:
- trunk/numpy/ma
- Files:
-
- 2 modified
-
core.py (modified) (5 diffs)
-
tests/test_core.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/numpy/ma/core.py
r8093 r8094 2793 2793 # When _mask.shape is not writable (because it's a void) 2794 2794 pass 2795 # Finalize the fill_value for structured arrays 2796 if self.dtype.names: 2797 if self._fill_value is None: 2798 self._fill_value = _check_fill_value(None, self.dtype) 2795 2799 return 2796 2800 … … 3570 3574 return _print_templates['short'] % parameters 3571 3575 return _print_templates['long'] % parameters 3572 #............................................ 3576 3577 3573 3578 def __eq__(self, other): 3574 3579 "Check whether other equals self elementwise" … … 5433 5438 def __new__(self, data, mask=nomask, dtype=None, fill_value=None): 5434 5439 dtype = dtype or data.dtype 5435 _data = ndarray.__new__(self, (), dtype=dtype, buffer=data.data) 5440 _data = ndarray((), dtype=dtype) 5441 _data[()] = data 5442 _data = _data.view(self) 5436 5443 if mask is not nomask: 5437 5444 try: … … 5464 5471 m = tuple(m) 5465 5472 if (not any(m)): 5466 return self._data.__ repr__()5473 return self._data.__str__() 5467 5474 r = self._data.tolist() 5468 5475 p = masked_print_option … … 5471 5478 else: 5472 5479 p = str(p) 5473 r = [(str(_), p)[_m] for (_, _m) in zip( self._data.tolist(), tuple(m))]5480 r = [(str(_), p)[_m] for (_, _m) in zip(r, m)] 5474 5481 return "(%s)" % ", ".join(r) 5475 5482 5476 __repr__ = __str__ 5483 def __repr__(self): 5484 m = self._mask 5485 if (m is nomask): 5486 return self._data.__repr__() 5487 m = tuple(m) 5488 if not any(m): 5489 return self._data.__repr__() 5490 p = masked_print_option 5491 if not p.enabled(): 5492 return self.filled(self.fill_value).__repr__() 5493 p = str(p) 5494 r = [(str(_), p)[_m] for (_, _m) in zip(r, m)] 5495 return "(%s)" % ", ".join(r) 5477 5496 5478 5497 def __iter__(self): -
trunk/numpy/ma/tests/test_core.py
r8093 r8094 504 504 "Test filled w/ mvoid" 505 505 ndtype = [('a', int), ('b', float)] 506 a = mvoid( np.array((1, 2)), mask=[(0, 1)], dtype=ndtype)506 a = mvoid((1, 2.), mask=[(0, 1)], dtype=ndtype) 507 507 # Filled using default 508 508 test = a.filled() … … 1457 1457 assert_equal(tt._fill_value, np.array(10)) 1458 1458 assert_equal(tuple(t.fill_value), (10, default_fill_value(0))) 1459 1460 def test_fillvalue_implicit_structured_array(self): 1461 "Check that fill_value is always defined for structured arrays" 1462 ndtype = ('b', float) 1463 adtype = ('a', float) 1464 a = array([(1.,), (2.,)], mask=[(False,), (False,)], 1465 fill_value=(np.nan,), dtype=np.dtype([adtype])) 1466 b = empty(a.shape, dtype=[adtype, ndtype]) 1467 b['a'] = a['a'] 1468 b['a'].set_fill_value(a['a'].fill_value) 1469 f = b._fill_value[()] 1470 assert(np.isnan(f[0])) 1471 assert_equal(f[-1], default_fill_value(1.)) 1459 1472 1460 1473 #------------------------------------------------------------------------------
