Skip to content

convert_units does not convert valid_min/valid_max #6411

Closed
@bouweandela

Description

@bouweandela

🐛 Bug Report

iris.cube.Cube.convert_units does not convert the valid_min/valid_max attributes. This can lead to the entire cube becoming masked if it is saved and loaded again because the data values are outside the valid range.

How To Reproduce

Steps to reproduce the behaviour:

In [1]: import iris

In [2]: import iris.cube

In [3]: iris.FUTURE.save_split_attrs = True

In [4]: cube = iris.cube.Cube([263], standard_name='air_temperature', units='K')

In [5]: cube.attributes.locals["valid_min"] = 0

In [6]: cube.convert_units("degrees_C")

In [7]: cube.data
Out[7]: array([-10.15])

In [8]: cube.attributes.locals["valid_min"]
Out[8]: 0

In [9]: iris.save(cube, target='tmp.nc')

In [10]: result = iris.load_cube("tmp.nc")

In [11]: result.data
Out[11]: 
masked_array(data=[--],
             mask=[ True],
       fill_value=9.969209968386869e+36,
            dtype=float64)

In [12]: result.attributes.locals["valid_min"]
Out[12]: np.float64(0.0)

Expected behaviour

I would expect convert_units to also convert the valid_min and valid_max attributes.

Environment

  • OS & Version: [e.g., Ubuntu 20.04 LTS]
  • Iris Version: 3.11

Additional context

Click to expand this section...
Please add additional verbose information in this section e.g., code, output, tracebacks, screenshots etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions