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

open_rasterio throws AttributeError after updating new xarray version 0.17.0 #254

Closed
bidhya opened this issue Feb 26, 2021 · 8 comments · Fixed by #255
Closed

open_rasterio throws AttributeError after updating new xarray version 0.17.0 #254

bidhya opened this issue Feb 26, 2021 · 8 comments · Fixed by #255
Labels
bug Something isn't working

Comments

@bidhya
Copy link

bidhya commented Feb 26, 2021

rioxarray.open_rasterio(raster) was working fine. Today I updated xarray to the new release 0.17.0 and now rioxarray.open_rasterio thows an AttributeError

Code Sample, a copy-pastable example if possible

rioxarray.open_rasterio(f'{maskdir}/{mask_tif}')


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/miniconda3/lib/python3.8/site-packages/xarray/core/common.py in __setattr__(self, name, value)
    267         try:
--> 268             object.__setattr__(self, name, value)
    269         except AttributeError as e:

AttributeError: 'DataArray' object has no attribute '_file_obj'

The above exception was the direct cause of the following exception:

AttributeError                            Traceback (most recent call last)
<ipython-input-5-93443f96a841> in <module>
      5 print(mask_tif)
      6 # Extract the water mask and set background to nan
----> 7 mask = rioxarray.open_rasterio(f'{maskdir}/{mask_tif}')

~/miniconda3/lib/python3.8/site-packages/rioxarray/_io.py in open_rasterio(filename, parse_coordinates, chunks, cache, lock, masked, mask_and_scale, variable, group, default_name, **open_kwargs)
    866 
    867     # Make the file closeable
--> 868     result._file_obj = manager
    869 
    870     return result

~/miniconda3/lib/python3.8/site-packages/xarray/core/common.py in __setattr__(self, name, value)
    274             ):
    275                 raise
--> 276             raise AttributeError(
    277                 "cannot set attribute %r on a %r object. Use __setitem__ style"
    278                 "assignment (e.g., `ds['name'] = ...`) instead of assigning variables."

AttributeError: cannot set attribute '_file_obj' on a 'DataArray' object. Use __setitem__ styleassignment (e.g., `ds['name'] = ...`) instead of assigning variables.

Environment Information

Tested on Linux
rioxarray 0.3.0 conda-forge
xarray 0.17.0 conda-forge

@bidhya bidhya added the bug Something isn't working label Feb 26, 2021
@dcherian
Copy link

it'd be nice if rioxarray could test against the git master version of xarray to catch these things before release.

@snowman2
Copy link
Member

it'd be nice if rioxarray could test against the git master version of xarray to catch these things before release.

Agreed.

@snowman2
Copy link
Member

Related: pydata/xarray#4809

@snowman2
Copy link
Member

@dcherian do you know what the recommended method for accessing the underlying file object in xarray is now?

We use it in a couple of places. For example:

  • to_raster to get the profile ref
  • nodata to get the nodata value ref
  • clip to clip from disk ref

@snowman2
Copy link
Member

pydata/xarray#2550. To be consistent, could add the filename in encoding["source"]. However, this isn't always helpful. For example WarpedVRT.

@dcherian
Copy link

@dcherian do you know what the recommended method for accessing the underlying file object in xarray is now?

I don't. cc @shoyer @jhamman @aurghs @alexamici

snowman2 added a commit to snowman2/rioxarray that referenced this issue Feb 26, 2021
snowman2 added a commit to snowman2/rioxarray that referenced this issue Feb 26, 2021
@snowman2
Copy link
Member

I have a patch in #255. Plan on adding the latest xarray to the CI soon.

@alexamici
Copy link
Contributor

I confirm that #255 looks correct. Thanks and sorry for the breakage.

Note that next release of xarray will include the new backend API with some changes that may impact you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants