Skip to content

Commit e90e8bc

Browse files
dcherianshoyer
authored andcommitted
ignore h5py 2.10.0 warnings and fix invalid_netcdf warning test. (#3301)
* ignore h5py 2.10.0 warnings and fix invalid_netcdf warning test. * Better fix. * fix fix. * remove comment. * Add docs. * Revert "Add docs." This reverts commit 14ae0b1.
1 parent 36cd02c commit e90e8bc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

xarray/tests/test_backends.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,7 @@ def test_encoding_unlimited_dims(self):
21632163

21642164
@requires_h5netcdf
21652165
@requires_netCDF4
2166+
@pytest.mark.filterwarnings("ignore:use make_scale(name) instead")
21662167
class TestH5NetCDFData(NetCDF4Base):
21672168
engine = "h5netcdf"
21682169

@@ -2173,16 +2174,25 @@ def create_store(self):
21732174

21742175
@pytest.mark.filterwarnings("ignore:complex dtypes are supported by h5py")
21752176
@pytest.mark.parametrize(
2176-
"invalid_netcdf, warns, num_warns",
2177+
"invalid_netcdf, warntype, num_warns",
21772178
[(None, FutureWarning, 1), (False, FutureWarning, 1), (True, None, 0)],
21782179
)
2179-
def test_complex(self, invalid_netcdf, warns, num_warns):
2180+
def test_complex(self, invalid_netcdf, warntype, num_warns):
21802181
expected = Dataset({"x": ("y", np.ones(5) + 1j * np.ones(5))})
21812182
save_kwargs = {"invalid_netcdf": invalid_netcdf}
2182-
with pytest.warns(warns) as record:
2183+
with pytest.warns(warntype) as record:
21832184
with self.roundtrip(expected, save_kwargs=save_kwargs) as actual:
21842185
assert_equal(expected, actual)
2185-
assert len(record) == num_warns
2186+
2187+
recorded_num_warns = 0
2188+
if warntype:
2189+
for warning in record:
2190+
if issubclass(warning.category, warntype) and (
2191+
"complex dtypes" in str(warning.message)
2192+
):
2193+
recorded_num_warns += 1
2194+
2195+
assert recorded_num_warns == num_warns
21862196

21872197
def test_cross_engine_read_write_netcdf4(self):
21882198
# Drop dim3, because its labels include strings. These appear to be
@@ -2451,6 +2461,7 @@ def skip_if_not_engine(engine):
24512461

24522462

24532463
@requires_dask
2464+
@pytest.mark.filterwarnings("ignore:use make_scale(name) instead")
24542465
def test_open_mfdataset_manyfiles(
24552466
readengine, nfiles, parallel, chunks, file_cache_maxsize
24562467
):

0 commit comments

Comments
 (0)