Skip to content

#768: Update environment to python 3.12#774

Merged
Matthew Mizielinski (matthew-mizielinski) merged 29 commits intomainfrom
768_update_cmor_numpy_iris_add_pyfive
Jan 29, 2026
Merged

#768: Update environment to python 3.12#774
Matthew Mizielinski (matthew-mizielinski) merged 29 commits intomainfrom
768_update_cmor_numpy_iris_add_pyfive

Conversation

@mo-gill
Copy link
Copy Markdown
Collaborator

Closes #768

@mo-gill Ed (mo-gill) added this to the CDDS v3.4.0 milestone Jan 19, 2026
@mo-gill Ed (mo-gill) self-assigned this Jan 19, 2026
@mo-gill
Copy link
Copy Markdown
Collaborator Author

In commit f21b5c4 I changed array to asarray as per the suggestion from this output generated from running the tests. Doing this fixed ~30 failing tests.

    def make_masked(data, shape, missing_value, dtype):
        logger = logging.getLogger(__name__)
        if dtype in [numpy.dtype('int32'), numpy.dtype('int64')]:
            logger.debug('Received data type "{}", converting to float32 to avoid issues later')
            dtype = numpy.dtype('float32')
    
>       data_array = numpy.array(data, dtype=dtype, copy=False)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       ValueError: Unable to avoid copy while creating an array as requested.
E       If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).
E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

mip_convert/mip_convert/variable.py:98: ValueError

@mo-gill
Copy link
Copy Markdown
Collaborator Author

Ed (mo-gill) commented Jan 20, 2026

When fixing unit tests, this doctest was failing:

___________________ [doctest] mip_convert.model_date.CdDate ____________________
019 
020     Dates are generated based optionally on the year, month, day, hour,
021     minute and second.
022 
023     >>> time1 = CdDate(1970, 1, 1, 0, 0)
024     >>> time2 = CdDate(1970, 1, 1, 0, 0, 0)
025 
026     They can be compared for identity:
027 
028     >>> time1 == time2
Expected:
    True
Got:
    np.True_

In commit bde4ce9 i added some casting from numpy bools to python bools to fix this.

Explanation: In numpy 2.0.0 bools went from being represented as True to np.True_, hence i added the casting to match the docstring.

More info on the numpy boolean change here numpy/numpy#26774

Edit:

I had a similar issue here:

_________________________ [doctest] mip_convert.plugins.base.data.processors.eos_insitu _________________________
942     rho: :class:`numpy.ndarray`
943         In-situ density (kg/m3)
944 
945     Examples
946     --------
947     Rounding is necessary to reproduce the following worked examples:
948 
949     * From the NEMO `eos_insitu` docstring
950 
951         >>> round(eos_insitu(40., 40., 10000.), 5)
Expected:
    1060.93299
Got:
    np.float64(1060.93299)

In this case i tried casting the result of eos_insitu to a float to match the expected type but this broke other tests (test_calc_rho_mean and test_zostoga_zero). It seems they were expecting numpy data types rather than floats (and whilst the original implementation was returning a numpy data type, the string representation of those types in numpy <2.0.0 was not explicitly declaring that (instead representing it as a float, which is why the doctest passed previous to numpy being updated to >2.0)

Hence i've just adjusted the docstring to expect a np.float64 instead in commit 91cd7ed
More info: https://numpy.org/neps/nep-0051-scalar-representation.html

@mo-gill Ed (mo-gill) marked this pull request as ready for review January 29, 2026 11:10
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following tests failed for me;

FAILED mip_convert/mip_convert/tests/test_functional/test_functional_cmip7/test_cmip7_fx_rootd_ti_u_hxy_lnd.py::TestCmip7_fx_rootd_ti_u_hxy_lnd::test_cmip7_fx_rootd
FAILED mip_convert/mip_convert/tests/test_functional/test_functional_cmip7/test_cmip7_fx_slthick_ti_sl_hxy_lnd.py::TestCmip7_fx_slthick_ti_sl_hxy_lnd::test_cmip7_efx_slthick

both due to presence of branded_variable attribute -- I think they just need updated reference data.

Comment thread cdds/cdds/tests/test_deprecated/test_transfer/test_dds.py
Comment thread run_all_tests Outdated
* #724: Create root depth processor

* #724: Update functional test with expected output
* #723: add a soil thickness calculation function.

* #723: Create functional test for slthick processor
@mo-gill
Copy link
Copy Markdown
Collaborator Author

Ed (mo-gill) commented Jan 29, 2026

Following tests failed for me;

FAILED mip_convert/mip_convert/tests/test_functional/test_functional_cmip7/test_cmip7_fx_rootd_ti_u_hxy_lnd.py::TestCmip7_fx_rootd_ti_u_hxy_lnd::test_cmip7_fx_rootd
FAILED mip_convert/mip_convert/tests/test_functional/test_functional_cmip7/test_cmip7_fx_slthick_ti_sl_hxy_lnd.py::TestCmip7_fx_slthick_ti_sl_hxy_lnd::test_cmip7_efx_slthick

both due to presence of branded_variable attribute -- I think they just need updated reference data.

Have now fixed these and added the reference data so they're passing in 54a80de

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and all tests pass

@matthew-mizielinski Matthew Mizielinski (matthew-mizielinski) merged commit 5282269 into main Jan 29, 2026
1 check passed
@matthew-mizielinski Matthew Mizielinski (matthew-mizielinski) deleted the 768_update_cmor_numpy_iris_add_pyfive branch January 29, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update cdds environment specification to use more recent iris, numpy and include pyfive

3 participants