File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,6 +67,17 @@ ndarray.tofile exception type
6767All ``tofile `` exceptions are now ``IOError ``, some were previously
6868``ValueError ``.
6969
70+ Invalid fill value exceptions
71+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+ Two changes to numpy.ma.core._check_fill_value:
73+
74+ * When the fill value is a string and the array type is not one of
75+ 'OSUV', TypeError is raised instead of the default fill value being used.
76+
77+ * When the fill value overflows the array type, TypeError is raised instead
78+ of OverflowError.
79+
80+
7081The ``doc/swig `` directory moved
7182~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7283The ``doc/swig `` directory has been moved to ``tools/swig ``.
Original file line number Diff line number Diff line change @@ -417,13 +417,18 @@ def _check_fill_value(fill_value, ndtype):
417417 dtype = ndtype )
418418 else :
419419 if isinstance (fill_value , basestring ) and (ndtype .char not in 'OSVU' ):
420- fill_value = default_fill_value (ndtype )
420+ err_msg = "Cannot set fill value of string with array of dtype %s"
421+ raise TypeError (err_msg % ndtype )
421422 else :
422- # In case we want to convert 1e+20 to int...
423+ # In case we want to convert 1e20 to int...
423424 try :
424- fill_value = np .array (fill_value , copy = False , dtype = ndtype )#.item()
425+ fill_value = np .array (fill_value , copy = False , dtype = ndtype )
425426 except OverflowError :
426- fill_value = default_fill_value (ndtype )
427+ # Raise TypeError instead of OverflowError. OverflowError
428+ # is seldom used, and the real problem here is that the
429+ # passed fill_value is not compatible with the ndtype.
430+ err_msg = "Fill value %s overflows dtype %s"
431+ raise TypeError (err_msg % (fill_value , ndtype ))
427432 return np .array (fill_value )
428433
429434
Original file line number Diff line number Diff line change @@ -1312,9 +1312,9 @@ def test_flat(self):
13121312
13131313#------------------------------------------------------------------------------
13141314class TestFillingValues (TestCase ):
1315- #
1315+
13161316 def test_check_on_scalar (self ):
1317- # Test _check_fill_value
1317+ # Test _check_fill_value set to valid and invalid values
13181318 _check_fill_value = np .ma .core ._check_fill_value
13191319 #
13201320 fval = _check_fill_value (0 , int )
@@ -1326,9 +1326,8 @@ def test_check_on_scalar(self):
13261326 assert_equal (fval , asbytes ("0" ))
13271327 fval = _check_fill_value (None , "|S3" )
13281328 assert_equal (fval , default_fill_value ("|S3" ))
1329- #
1330- fval = _check_fill_value (1e+20 , int )
1331- assert_equal (fval , default_fill_value (0 ))
1329+ self .assertRaises (TypeError , _check_fill_value , 1e+20 , int )
1330+ self .assertRaises (TypeError , _check_fill_value , 'stuff' , int )
13321331
13331332 def test_check_on_fields (self ):
13341333 # Tests _check_fill_value with records
You can’t perform that action at this time.
0 commit comments