home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 586959508

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/3348#issuecomment-586959508 https://api.github.com/repos/pydata/xarray/issues/3348 586959508 MDEyOklzc3VlQ29tbWVudDU4Njk1OTUwOA== 37239554 2020-02-17T11:52:32Z 2020-02-17T11:52:32Z NONE

The problem is still there, as it is quite unexpected.

I hacked it using .astype() directly in the np.array

Test code

```python import xarray as xr

da = xr.DataArray( np.arange(56).reshape((7, 8)), coords={ 'x': list('abcdefg'), 'y': 10 * np.arange(8) }, dims=['x', 'y'], attrs={"at_str":"at1_value","at_float":123.,"at_int":123} )

print("Original xr.DataArray") print(f"attrs: {da.attrs}") print(f"dtype: {da.dtype}")

print(f"\nAfter casting to int64: {da.astype(np.int64).attrs}" ) print(f"After casting to int32: {da.astype(np.int32).attrs}" ) print(f"After casting to float32: {da.astype(np.float32).attrs}")

da.values = da.values.astype(np.float32) print("\nChanging the np.array") print(f"attrs: {da.attrs}") print(f"dtype: {da.dtype}") ```

Output:

``` Original xr.DataArray attrs: {'at_str': 'at1_value', 'at_float': 123.0, 'at_int': 123} dtype: int64

After casting to int64: {} After casting to int32: {} After casting to float32: {}

Changing the np.array attrs: {'at_str': 'at1_value', 'at_float': 123.0, 'at_int': 123} dtype: float32 ```

xr.show_versions()

``` INSTALLED VERSIONS


commit: None python: 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 14:38:56) [Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 18.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.6.2

xarray: 0.15.0 pandas: 1.0.1 numpy: 1.18.1 scipy: 1.3.0 netCDF4: 1.5.1.2 pydap: installed h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.2.1 dask: None distributed: None matplotlib: 3.1.0 cartopy: None seaborn: 0.9.0 numbagg: None setuptools: 41.0.1 pip: 19.1.1 conda: None pytest: 5.0.1 IPython: 7.7.0 sphinx: None ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  499196320
Powered by Datasette · Queries took 0.813ms · About: xarray-datasette