Skip to content

test_Saver: DeprecationWarning: elementwise comparison failed #4374

@trexfeathers

Description

@trexfeathers

📰 Custom Issue

Running iris.tests.unit.fileformats.netcdf.test_Saver.Test_write.test_zlib() raises the following DeprecationWarning:

.../iris/fileformats/netcdf.py:2762: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
  contains_value = fill_value is not None and fill_value in data

This appears to stem from the fact that we are patching the netCDF4 module, which means that a MagicMock is passed as the fill_value.

Patching

api = self.patch("iris.fileformats.netcdf.netCDF4")
with Saver("/dummy/path", "NETCDF4") as saver:
saver.write(cube, zlib=True)

Point of warning

def store(data, cf_var, fill_value):
cf_var[:] = data
is_masked = ma.is_masked(data)
contains_value = fill_value is not None and fill_value in data
return is_masked, contains_value


To make sure the test continues to work, we will need to find a way for the MagicMock to be recognised as an appropriate value for Numpy elementwise comparison. But I have no idea how to do this when the MagicMock is coming from a patch!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions