-
Notifications
You must be signed in to change notification settings - Fork 39
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.real_datetime not pandas compatible #77
Comments
Thanks @fmaussion. I think it's still important to distinguish between objects that subclass I would not expect |
It looks like all they are missing is a nanosecond attribute, which can just always be 0 for it to work as expected. |
python datetime objects don't have a nanosecond attribute either |
They indeed don't, but pandas assumes that whenever an object is "PyDateTime_Check(val) and not PyDateTime_CheckExact(val)", i.e. a subclass of datetime, that it has a nanosecond attribute, which is what causes the error in the first place: |
So this is a bug in pandas then? |
Pandas just closed this issue on their side.
|
Sorry for likely prompting that issue to be closed there...one could try to fix this issue in pandas, but I understand to some extent their pushback. They do not make any guarantees that non- Barring rolling back the change in #66 to add
At least for now, NumPy seems to handle subclasses of |
Yes, I don't worry too much about workarounds - currently we are running with the But as I said, I just don't understand dates in python well enough to make any recommendation here. In this perspective I am like most scientists I guess: there are way too many date formats in python. They are all equivalent to me, until I find out they are not ;-) |
You're definitely not the only one :). I'm sorry if I came across as being in support of doing nothing in response to this issue.
I agree; in hindsight #66 effectively created another one, for arguably little gain (and clearly at least one regression). From my perspective I think cftime should at least consider the option of reverting back to by default using pure As I understand it, in addition to creating Ultimately, I think the benefits of returning standard Python That's my two cents, but I am not a core developer of cftime, so take that with a grain of salt. |
I do think that the actual issue in this case is on the pandas side. As they are the ones assuming that every subclass of datetime automatically has to have a nanosecond attribute, which there is absolutely no guarantee for. |
@TimoRoth I understand that it would fix things in pandas if that was allowed, but I think it's important to note that pandas doesn't explicitly say they will support subclasses of datetime objects, which is the reason for their reluctance. Therefore I'm not sure I would frame it as a "bug" or "regression" in pandas; it would be more of a request for them to relax their assumptions. The change that caused this was in cftime (and was made quite recently). For that reason I think we should at least reflect on whether that was a good decision before approaching pandas again. |
For what it's worth though, I will note that others apparently would like something of this sort to be supported in pandas too -- this issue seems related: pandas-dev/pandas#21142. |
@TimoRoth how much of an effort would it be to send a patch in Pandas? Jeff Reback seemed opened to it (pandas-dev/pandas#23419 (comment)) Let's just hope it doesn't imply messing around with C code... |
Sorry @jswhit I was a little confused by your comment, though I can't seem to find it on GitHub anymore. As a subclass of That being said, I really don't feel very strongly about this, so I don't want to belabor the discussion. I merely thought given the recency of the change that it might warrant reconsidering in this case, but I see the other side of the argument too (i.e. that one might want |
I deleted that comment after I realized it was completely off base, sorry. You are right that this particular change only enabled the extra two attributes (dayofwk, dayofyr). I would still prefer the issue be addressed in pandas, but I'm not opposed to adding a bogus nanosecond attribute as a workaround. |
Perfect, thanks. Hopefully things work out in pandas, but it's good to have that as a fallback option here. |
@fmaussion, can you verify that pull request #95 (branch |
add bogus nanosecond attribute to real_datetime (issue #77)
I know I'm late on this, but thanks for adding the workaround @jswhit. |
Thx for your answer, but I found something wrong: Maybe the right code shoud be below: |
I think it depends on your purpose. The motivation for using the integer range as the values and the times as the |
See pandas-dev/pandas#23419 for context.
The issue is following:
Fails with
@spencerkclark says that this is due to the fact that netcdf4 now returns cftime objects per default (always). I guess it is a necessary change (having different time objects to deal with depending on the calendar is a pain), but it makes me wonder about the level of compatibility between cftime objects and the rest of the pydata stack.
I'm no specialist at all here, so I don't know what it would involve, but it would be nice if cftime objects could be handled by pandas.
The easiest fix seems to simply add a
nanoseconds
attribute to thecftime.real_datetime
objects.The text was updated successfully, but these errors were encountered: