Closed
Description
What happened?
AttributeError: 'DataArray' object has no attribute '_data'
What did you expect to happen?
No error.
Minimal Complete Verifiable Example
# 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)
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
Relevant log output
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
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