Select to view content in your preferred language

Xarray library core functions now failing in Pro 3.2

1088
2
Jump to solution
11-08-2023 12:10 AM
LewisTrotter
Occasional Contributor

Hello,

The recent Pro 3.2 update has broken some of the basic core features of the Xarray Python library which we rely on quite heavily and for years have had no issues with in Pro.

I have a netcdf file with x, y and time dims (see attached). I put it through the following code in a Pro notebook:

import xarray as xr
# load netcdf
ds = xr.open_dataset(r"C:\R2016-02-12.nc")

# this results in error now
ds.resample(time='1YS').mean()

# this results in error now
ds.interpolate_na('time').mean()

The resample function results in a type error: __init__() got an unexpected keyword argument 'base'. Looking on the net indicates this could be due to an incompatibility between Xarray and python versions.

The interpolate_na fucntion returns an attribute error: 'DatetimeIndex' object has no attribute 'is_monotonic'. I have tried on several netcdfs with multiple dates and same issue.

All data tested worked a week ago in Pro 3.1 (and earlier), so something has happened with Pro 3.2.

Normally I'd find a work around but because these functions are fundamental to the Xarray library (and to our plugins!) I have submitted here.

Any advice or knowledge on this would be appreciated.

Lewis

 

 

1 Solution

Accepted Solutions
BrianClee
Esri Contributor

Hi Lewis thank you for this report, looks like our update to pandas 2 broke some xarray functionality. I was able to reproduce your error thanks to the data you supplied. I have a workaround that resolves the issue on my machine, could you try the following:

  • Create a clone of arcgispro-py3, this can be done through pro's Package Manager UI in the settings, or through the Python Command Prompt. 
    • If using the Python Command Prompt use this syntax:
    • conda create --clone arcgispro-py3 -n clone-name --pinned
  • Launch the Python Command Prompt (if its not already open)
  • Switch to your clone with `proswap clone-name`
    • This will make your clone the default environment when you launch Pro
  • Finally update xarray with:
    • conda install xarray --no-deps -y
    • This will only update xarray to the latest 2023.6.0 version
  • Using this environment your above code should work now

I'm working on getting this included in the 3.2.1 patch list to update arcgispro-py3's version of xarray but in the meantime the above workaround should help.

I have also attached my Python Command Prompt console log, this shows the commands I used to clone, swap to the clone, install xarray, and test the workflow (I also tested in the Pro app).

 

 

View solution in original post

2 Replies
LewisTrotter
Occasional Contributor

Further information: this appears to be an issue with pandas/xarray

https://github.com/pydata/xarray/issues/8282

 

0 Kudos
BrianClee
Esri Contributor

Hi Lewis thank you for this report, looks like our update to pandas 2 broke some xarray functionality. I was able to reproduce your error thanks to the data you supplied. I have a workaround that resolves the issue on my machine, could you try the following:

  • Create a clone of arcgispro-py3, this can be done through pro's Package Manager UI in the settings, or through the Python Command Prompt. 
    • If using the Python Command Prompt use this syntax:
    • conda create --clone arcgispro-py3 -n clone-name --pinned
  • Launch the Python Command Prompt (if its not already open)
  • Switch to your clone with `proswap clone-name`
    • This will make your clone the default environment when you launch Pro
  • Finally update xarray with:
    • conda install xarray --no-deps -y
    • This will only update xarray to the latest 2023.6.0 version
  • Using this environment your above code should work now

I'm working on getting this included in the 3.2.1 patch list to update arcgispro-py3's version of xarray but in the meantime the above workaround should help.

I have also attached my Python Command Prompt console log, this shows the commands I used to clone, swap to the clone, install xarray, and test the workflow (I also tested in the Pro app).