Skip to content

Dataset character coordinates change to object upon use in Dataset #2658

Closed
@equaeghe

Description

@equaeghe

Code Sample

>>> import xarray as xr

>>> test = xr.Dataset(coords={'xy': ['x', 'y']})

>>> test
<xarray.Dataset>
Dimensions:  (xy: 2)
Coordinates:
  * xy       (xy) <U1 'x' 'y'  # NOTE '<U1' dtype
Data variables:
    *empty*

>>> test['test'] = xr.DataArray(np.array([0, 0]), dims=['xy'])

>>> test
<xarray.Dataset>
Dimensions:  (xy: 2)
Coordinates:
  * xy       (xy) object 'x' 'y'  # NOTE 'object' dtype
Data variables:
    test     (xy) int64 0 0

Problem description

The coordinate dtype changes from <U1 to object.

Expected Output

The coordinate dtype should not change.

Output of xr.show_versions()

/usr/lib64/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.83-gentoo
machine: x86_64
processor: Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz
byteorder: little
LC_ALL: None
LANG: nl_BE.UTF-8
LOCALE: nl_BE.UTF-8

xarray: 0.10.8
pandas: 0.19.1
numpy: 1.14.5
scipy: 0.19.1
netCDF4: 1.3.1
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: None
distributed: None
matplotlib: 2.2.2
cartopy: None
seaborn: None
setuptools: 36.7.2
pip: 9.0.1
conda: None
pytest: 3.2.2
IPython: 5.4.1
sphinx: 1.7.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions