We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
AttributeError: 'DataArray' object has no attribute '_data'
No error.
# https://github.com/corteva/rioxarray/blob/21284f67db536d9c104aa872ab0bbc261259e59e/test/integration/test_integration_rioxarray.py#L1818-L1844 import numpy import xarray import rioxarray test_da = xarray.DataArray( numpy.zeros((5, 5)), dims=("y", "x"), coords={"y": numpy.arange(1, 6), "x": numpy.arange(2, 7)}, ) test_da.values[1, 1] = -1.1 test_nd = test_da.rio.write_nodata(-1.1) test_nd.rio.write_transform( Affine.from_gdal(425047, 3.0, 0.0, 4615780, 0.0, -3.0), inplace=True ) test_nd.rio.write_crs("EPSG:4326", inplace=True) test_nd.rio.to_raster("dtype.tif", dtype=numpy.uint8)
rioxarray/raster_writer.py:288: in to_raster data = encode_cf_variable(out_data).values.astype(numpy_dtype) /usr/share/miniconda/envs/test/lib/python3.9/site-packages/xarray/conventions.py:296: in encode_cf_variable var = coder.encode(var, name=name) /usr/share/miniconda/envs/test/lib/python3.9/site-packages/xarray/coding/times.py:690: in encode ) or contains_cftime_datetimes(variable): /usr/share/miniconda/envs/test/lib/python3.9/site-packages/xarray/core/common.py:1818: in contains_cftime_datetimes return _contains_cftime_datetimes(var._data) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <xarray.DataArray (y: 5, x: 5)> array([[ 0. , 0. , 0. , 0. , 0. ], [ 0. , -1.1, 0. , 0. , 0. ], [... (y) int64 1 2 3 4 5 * x (x) int64 2 3 4 5 6 spatial_ref int64 0 Attributes: _FillValue: -1.1 name = '_data' def __getattr__(self, name: str) -> Any: if name not in {"__dict__", "__setstate__"}: # this avoids an infinite loop when pickle looks for the # __setstate__ attribute before the xarray object is initialized for source in self._attr_sources: with suppress(KeyError): return source[name] > raise AttributeError( f"{type(self).__name__!r} object has no attribute {name!r}" ) E AttributeError: 'DataArray' object has no attribute '_data' /usr/share/miniconda/envs/test/lib/python3.9/site-packages/xarray/core/common.py:276: AttributeError
No response
This is the latest version of xarray/numpy (pre-release versions).
https://github.com/corteva/rioxarray/actions/runs/4458288974/jobs/7829970587
The text was updated successfully, but these errors were encountered:
Probably from #7494. encode_cf_variable only accepts Variables. Replace
encode_cf_variable
data = encode_cf_variable(out_data).values.astype(numpy_dtype)
with
data = encode_cf_variable(out_data.variable).values.astype(numpy_dtype)
should fix the error.
mypy should have caught this a while ago when #7374 went in, does out_data have defined type hints?
out_data
Sorry, something went wrong.
^ 👍
Passing .variable should fix it but the real issue here is that you're using private API because there is no public API: #4412
.variable
That would be a nice PR!
cc @JessicaS11 @scottyhq
Thanks @Illviljan 👍
mypy should have caught this a while ago
Type hints are likely incomplete/inexact in some places in rioxarray code.
No branches or pull requests
What happened?
What did you expect to happen?
No error.
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
This is the latest version of xarray/numpy (pre-release versions).
https://github.com/corteva/rioxarray/actions/runs/4458288974/jobs/7829970587
The text was updated successfully, but these errors were encountered: