-
Notifications
You must be signed in to change notification settings - Fork 40
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
[Bug]: TypeError: unsupported operand type(s) for +: 'cftime._cftime.DatetimeNoLeap' and 'NoneType'
on Linux
#328
Comments
what is the expected behavior here? PR #330 converts the input to a masked array if a nan or inf is present, so that a masked array of dates is returned. |
@jswhit Thanks for the PR! I'm not sure what the expected behavior is besides a successful output with an array of cftime objects. I would need to re-run this code on a non-Linux machine to see what the output looks like. |
Yes, that would be interesting. I don't see how this code would work on any platform without the fix in PR #330. |
Minimum example (no xarray)import cftime
import numpy as np
time_encoded = np.array(
[3.477600e08, 3.476736e08, 3.475872e08, 2.685312e08, np.nan, np.nan]
)
time_units = "seconds since 0488-02-01 00:00:00"
time_decoded = cftime.num2date(
time_encoded, time_units, "standard", only_use_cftime_datetimes=True
)
print(time_decoded) Output (on MacOS)Same code breaks on Linux with the bug described in the title. <ipython-input-23-983092b57b88>:6: RuntimeWarning: invalid value encountered in cast
time_decoded = cftime.num2date(
[cftime.DatetimeGregorian(499, 2, 8, 0, 0, 0, 0, has_year_zero=False)
cftime.DatetimeGregorian(499, 2, 7, 0, 0, 0, 0, has_year_zero=False)
cftime.DatetimeGregorian(499, 2, 6, 0, 0, 0, 0, has_year_zero=False)
cftime.DatetimeGregorian(496, 8, 5, 0, 0, 0, 0, has_year_zero=False)
cftime.DatetimeGregorian(488, 2, 1, 0, 0, 0, 0, has_year_zero=False)
cftime.DatetimeGregorian(488, 2, 1, 0, 0, 0, 0, has_year_zero=False)] The last two time coordinates are Also notice Expected BehaviorShould they still be |
I suspect that the problem is that the operations with NaNs can give compiler-dependent results (hence the difference with gcc (linux) and clang (macosx)). I think the way to avoid this is to either raise an exception if nans or infs are found, or treat them as missing values (as PR #330 does). |
@jswhit Actually, would it make sense to maintain the |
@tomvothecoder |
if you do want to convert the missing values back to nans, you can just do |
I see what you're saying. In this context, the output must be an array containing all For the rare cases where time coordinates might have I wonder how Xarray will handle the possible |
Thank you for investigating this issue! What date will be returned when the input value is a As a user, I like NaN infilling because it helps to ensure that I don't accidentally interpret the NaN value as @jswhit – is there a downside to returning a |
@pochedia a numpy masked array is returned with dtype=object. The default fill_value is '?' (a string), so if the users code converts the masked array to a regular ndarray that's the data value they would see. (but as I mentioned above it's easy to manually change this to NaN) |
closed by PR #330. Feel free to re-open if this solution does not meet your needs. |
Hello, an xCDAT user found a bug with
cftime
on Linux. The time coordinates of the dataset containnan
values. When the user tries to convert the time coordinates tocftime
, it breaks.We verified the MVCE below works on Mac (M2) and not on Linux. Any ideas on why this happening? Thanks!
Minimal Complete Verifiable Example (MVCE)
Example dataset: subset.nc.zip
The ds file looks like:
and the time axis:
Relevant log output
Environment
The text was updated successfully, but these errors were encountered: