-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
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
string coordinate gets converted to object coordinate upon addition of variable to dataset #627
Comments
Thanks for the report -- this does seem like a bug to me. We do end up converting from fixed width strings to object quite often (to get around limitations of NumPy's strings), but adding in a variable should not change the type of any existing variables. It's possible the best fix here will be to convert all string arrays into an object type as soon as they are loaded into xray objects. |
object arrays look fine to me, but I don't have a strong opinion either. |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity |
The bug is still valid. |
Given that this is an index, are we dependent on pandas here? |
If this isn't an upstream pandas issue, let's reopen (I'm not sure why @stalebot closed this - looks like it's not respecting the comments?) |
I don't know whether it's pandas or xarray's fault, but the behavior is definitely still present. |
This issue appears to have been resolved: In [1]: import xarray as xr
In [2]: import numpy as np
In [3]: ds = xr.Dataset({"1": xr.DataArray(np.zeros(3), dims=["a"], coords={"a": list("xyz")})})
In [4]: ds
Out[4]:
<xarray.Dataset>
Dimensions: (a: 3)
Coordinates:
* a (a) <U1 'x' 'y' 'z'
Data variables:
1 (a) float64 0.0 0.0 0.0
In [5]: ds["2"] = xr.DataArray(np.zeros(2), dims=["a"], coords={"a": list("xy")})
In [6]: ds
Out[6]:
<xarray.Dataset>
Dimensions: (a: 3)
Coordinates:
* a (a) <U1 'x' 'y' 'z'
Data variables:
1 (a) float64 0.0 0.0 0.0
2 (a) float64 0.0 0.0 nan I tested this with xarray: 0.17.0
pandas: 1.2.3
numpy: 1.20.1 Should we close this? |
I have not used xarray recently, so I have no opinion there. |
it seems this should have been closed by #4759 (bisecting reveals that as the first good commit) |
With the current HEAD, consider
This outputs
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...
The text was updated successfully, but these errors were encountered: