Skip to content

string coordinate gets converted to object coordinate upon addition of variable to dataset #627

Closed
@anntzer

Description

@anntzer

With the current HEAD, consider

import numpy as np
from xray import *

ds = Dataset({"1": DataArray(np.zeros(3), dims=["a"], coords={"a": list("xyz")})})
print(ds)
ds["2"] = DataArray(np.zeros(2), dims=["a"], coords={"a": list("xy")})
print(ds)

This outputs

<xray.Dataset>
Dimensions:  (a: 3)
Coordinates:
  * a        (a) <U1 'x' 'y' 'z'
Data variables:
    1        (a) float64 0.0 0.0 0.0
<xray.Dataset>
Dimensions:  (a: 3)
Coordinates:
  * a        (a) object 'x' 'y' 'z'
Data variables:
    1        (a) float64 0.0 0.0 0.0
    2        (a) float64 0.0 0.0 nan

Note that the dtype of the a coordinate got changed after the assignment.

Python3.5, numpy 1.10.1, xray master (6ea7eb2)

With 0.6.0 the coordinate is of object dtype both before and after. I forgot why I tried master but I must have had a good reason...

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