Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Xarray Private API and remove pinning #381

Closed
pilotchute opened this issue Mar 23, 2023 · 4 comments · Fixed by #492
Closed

Remove Xarray Private API and remove pinning #381

pilotchute opened this issue Mar 23, 2023 · 4 comments · Fixed by #492
Assignees
Labels
bug Something isn't working support Support request opened by outside user/collaborator

Comments

@pilotchute
Copy link
Contributor

Describe the bug
Xarray 2023.03.0 breaks tests due to a call on line 1818 of xarray/core/common.py

To Reproduce
run tests

Expected behavior
no error

Screenshots
Failing test run
OS:
Both MacOS and Ubuntu

Environment
n/a

@pilotchute pilotchute added bug Something isn't working support Support request opened by outside user/collaborator labels Mar 23, 2023
pilotchute pushed a commit that referenced this issue Mar 23, 2023
Signed-off-by: pilotchute <akootz@ucar.edu>
@anissa111
Copy link
Member

This seems relevant: pydata/xarray#7645

@dcherian
Copy link
Contributor

xr.core.common.contains_cftime_datetimes(d_arr)

This is private API, you should vendor it though the current version isn't the most friendly for vendoring. So perhaps reimplement it.

Also I recommend updating your upstream-dev-ci (e.g. corteva/rioxarray#654)

pilotchute pushed a commit to NCAR/geocat-viz that referenced this issue Mar 25, 2023
Signed-off-by: pilotchute <akootz@ucar.edu>
@anissa111 anissa111 changed the title Xarray ended support for python 3.8, and is breaking our tests for python 3.9+. Remove Xarray Private API and remove pinning May 18, 2023
@anissa111 anissa111 self-assigned this May 18, 2023
@cyschneck
Copy link
Contributor

Part of this issue appears in 02-more_advanced_functionality and prevents graphs from being generated

# Minimal Example:
from geocat.comp import climatology_average
import xarray as xr
import geocat.datafiles as gdf

nc_file = gdf.get('netcdf_files/atm.20C.hourly6-1990-1995-TS.nc')
ds = xr.open_dataset(nc_file)
ds = ds.isel(member_id=0)  # select one model from the ensemble

temp = ds.TS
monthly_temp = climatology_average(temp, freq='month')

Throws: AttributeError: 'DataArray' object has no attribute '_data'

The issue seems to come from contains_cftime_datetimes no longer accepts DataArrays. So now it expects xarray.Variable

For now, while running locally by changing xr.core.common.contains_cftime_datetimes(d_arr) to xr.core.common.contains_cftime_datetimes(d_arr.variable) fixes the error and can now generate graphs in the geocat-tutorials

Until there is a public API this can be change in /home/user/miniconda3/envs/geocat-tutorials/lib/python3.10/site-packages/geocat/comp/climatologies.py on conda to run the tutorial

def _contains_datetime_like_objects(d_arr):
    """Check if a variable contains datetime like objects (either
    np.datetime64, or cftime.datetime)"""
    return np.issubdtype(
        d_arr.dtype,
        np.datetime64) or xr.core.common.contains_cftime_datetimes(d_arr.variable)

@cyschneck
Copy link
Contributor

Currently, an open issue on geocat-comp. Can get around the error by setting xarray<=2023.02.0

A more general solution

data = encode_cf_variable(out_data).values.astype(numpy_dtype)
with
data = encode_cf_variable(out_data.variable).values.astype(numpy_dtype)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working support Support request opened by outside user/collaborator
Projects
None yet
5 participants