-
-
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
cftime.DatetimeNoLeap incorrectly decoded from netCDF file #8298
Comments
This bug is causing me pain, especially in the index. For the array I can just do I would prefer to fix the bug, but I actually don't know where in xarray to look. Perhaps @kmuehlbauer you might know where to point me? :) |
@TomNicholas sorry for not commenting on this earlier. As far as I can tell this is just an issue with the HTML repr, i.e. it should not affect indexing or otherwise interacting with the time coordinate ( |
Thanks @spencerkclark
Oh really?? So I'm trying to coerce unecessarily? But is the dtype of the array backing the |
Like this looks like the wrong type of array array([cftime.DatetimeNoLeap(347, 2, 1, 0, 0, 0, 0, has_year_zero=True),
cftime.DatetimeNoLeap(347, 3, 1, 0, 0, 0, 0, has_year_zero=True),
cftime.DatetimeNoLeap(362, 1, 1, 0, 0, 0, 0, has_year_zero=True)],
dtype=object) |
That's correct :) |
Yes, this is expected. As an aside, if you need to coerce to |
(as an aside, |
@TomNicholas Sorry Tom, was already AFK. Would also have referred to @spencerkclark's expertise, though. |
Thank you everyone for your help! ❤️ I am still confused about what the difference between cftime.datetime(1999, 1, 1, 0, 0, 0, 0, calendar='noleap', has_year_zero=True) and cftime.DatetimeNoLeap(347, 2, 1, 0, 0, 0, 0, has_year_zero=True) is, but I was now able to do the operation I needed to do. Should we leave this open to track the repr not being super clear, or just close? |
I think we can close. Though this could be a good opportunity to update our docs to be more clear about CFTime handling :) |
For sure! From the perspective of cftime they are the same, but for historical reasons xarray continues to use the calendar-specific subclasses. To adopt the use of calendar-aware I am fine with closing. Maybe if this kind of confusion around |
It seems I can't concatenate this index either: dates = [
cftime.DatetimeNoLeap.strptime('1999-01', '%Y-%m', calendar='noleap', has_year_zero=True),
cftime.DatetimeNoLeap.strptime('1999-01', '%Y-%m', calendar='noleap', has_year_zero=True),
]
da = xr.DataArray(data=[0, 1], coords={'time': ('time', dates)}, dims=['time'])
print(da)
xr.concat([da, da], dim='time')
EDIT: And if I try to drop the index first I get a dataarray object which can be printed as a string but can't be displayed using the HTML repr: concatted = xr.concat([da.drop_indexes('time'), da.drop_indexes('time')], dim='time', |
@TomNicholas from the xarray point of view this essentially is the same issue since
Concatenation should work OK with indexes composed of |
What happened?
I have been given a netCDF file (I think it's netCDF3) which when I open it does not decode the time variable in the way I expected it to. The time coordinate created is a numpy object array
What did you expect to happen?
I expected it to automatically create a coordinate backed by a
CFTimeIndex
object, not aCFTimeIndex
object wrapped inside another array type.Minimal Complete Verifiable Example
The original problematic file is 455MB (I can share it if necessary), but I can create a small netCDF file that displays the same issue.
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
The text was updated successfully, but these errors were encountered: