Skip to content

Commit f00ab9b

Browse files
mzuehlkeshoyer
authored andcommitted
Discovered conflicting _FillValue and missing_value, but both are NaN (#998)
* fixes #997 * use pd.isnull instead of np.isnan * add note to "What's New"
1 parent 69ac511 commit f00ab9b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/whats-new.rst

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ Bug fixes
6565
(:issue:`873`).
6666
By `Stephan Hoyer <https://github.com/shoyer>`_.
6767

68+
- Fix issues with variables where both attributes ``_FillValue`` and
69+
``missing_value`` are set to ``NaN`` (:issue:`997`).
70+
By `Marco Zühlke <https://github.com/mzuehlke>`_.
71+
6872
.. _whats-new.0.8.2:
6973

7074
v0.8.2 (18 August 2016)

xarray/core/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def equivalent(first, second):
9999
if isinstance(first, np.ndarray) or isinstance(second, np.ndarray):
100100
return ops.array_equiv(first, second)
101101
else:
102-
return first is second or first == second
102+
return first is second or first == second or (pd.isnull(first) and pd.isnull(second))
103103

104104

105105
def peek_at(iterable):

xarray/test/test_conventions.py

+14
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ def test_decode_cf_with_conflicting_fill_missing_value(self):
259259
self.assertRaisesRegexp(ValueError, "_FillValue and missing_value",
260260
lambda: conventions.decode_cf_variable(var))
261261

262+
var = Variable(['t'], np.arange(10),
263+
{'units': 'foobar',
264+
'missing_value': np.nan,
265+
'_FillValue': np.nan})
266+
var = conventions.decode_cf_variable(var)
267+
self.assertIsNotNone(var)
268+
269+
var = Variable(['t'], np.arange(10),
270+
{'units': 'foobar',
271+
'missing_value': np.float32(np.nan),
272+
'_FillValue': np.float32(np.nan)})
273+
var = conventions.decode_cf_variable(var)
274+
self.assertIsNotNone(var)
275+
262276
@requires_netCDF4
263277
def test_decode_cf_datetime_non_iso_strings(self):
264278
# datetime strings that are _almost_ ISO compliant but not quite,

0 commit comments

Comments
 (0)