Example #1
0
def test_decode_cf_with_conflicting_fill_missing_value():
    expected = Variable(['t'], [np.nan, np.nan, 2], {'units': 'foobar'})
    var = Variable(['t'], np.arange(3),
                   {'units': 'foobar',
                    'missing_value': 0,
                    '_FillValue': 1})
    with warnings.catch_warnings(record=True) as w:
        actual = conventions.decode_cf_variable('t', var)
        assert_identical(actual, expected)
        assert 'has multiple fill' in str(w[0].message)

    expected = Variable(['t'], np.arange(10), {'units': 'foobar'})

    var = Variable(['t'], np.arange(10),
                   {'units': 'foobar',
                    'missing_value': np.nan,
                    '_FillValue': np.nan})
    actual = conventions.decode_cf_variable('t', var)
    assert_identical(actual, expected)

    var = Variable(['t'], np.arange(10),
                   {'units': 'foobar',
                    'missing_value': np.float32(np.nan),
                    '_FillValue': np.float32(np.nan)})
    actual = conventions.decode_cf_variable('t', var)
    assert_identical(actual, expected)
Example #2
0
 def test_decode_cf_with_conflicting_fill_missing_value(self):
     var = Variable(['t'], np.arange(10),
                    {'units': 'foobar',
                     'missing_value': 0,
                     '_FillValue': 1})
     self.assertRaisesRegexp(ValueError, "_FillValue and missing_value",
                             lambda: conventions.decode_cf_variable(var))
Example #3
0
 def test_decode_cf_with_multiple_missing_values(self):
     original = Variable(['t'], [0, 1, 2],
                         {'missing_value': np.array([0, 1])})
     expected = Variable(['t'], [np.nan, np.nan, 2], {})
     with warnings.catch_warnings(record=True) as w:
         actual = conventions.decode_cf_variable('t', original)
         assert_identical(expected, actual)
         assert 'has multiple fill' in str(w[0].message)
Example #4
0
    def test_decode_cf_with_conflicting_fill_missing_value(self):
        var = Variable(['t'], np.arange(10),
                       {'units': 'foobar',
                        'missing_value': 0,
                        '_FillValue': 1})
        with raises_regex(ValueError, "_FillValue and missing_value"):
            conventions.decode_cf_variable('t', var)

        var = Variable(['t'], np.arange(10),
                       {'units': 'foobar',
                        'missing_value': np.nan,
                        '_FillValue': np.nan})
        var = conventions.decode_cf_variable('t', var)
        self.assertIsNotNone(var)

        var = Variable(['t'], np.arange(10),
                       {'units': 'foobar',
                        'missing_value': np.float32(np.nan),
                        '_FillValue': np.float32(np.nan)})
        var = conventions.decode_cf_variable('t', var)
        self.assertIsNotNone(var)