-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: (GH3863) Timestamp.min and Timestamp.max return a valid Timestamp #3902
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
Conversation
would you add a mention in release notes under API? |
also I think you might mention min/max here: http://pandas.pydata.org/pandas-docs/dev/gotchas.html#minimum-and-maximum-timestamps |
Could you also add a testcase :) |
maybe instead of the actual values, should define them as with min + 1 (to avoid NaT conflict) |
@jreback: Good idea about using np.iinfo - as a matter of fact, that's what I did initially but then I found that the constants were already defined but commented out. I'll add the change to the release notes and gotchas as well. @hayd: With regards to tests - I'm not entirely sure what to test there? It is basically 2 fields. I can add some tests that assert the fields value... |
Interestingly enough, on osx
This could be the reason why the magic number is used - and also mentioned in the gotchas. |
Are you just asserting that these don't raise? (i.e. call them in a test is enough)
Actually check they equals whatever they're supposed to equal? |
@SleepingPills can you hook up travis, then recommit this? |
@@ -388,6 +388,13 @@ cpdef object get_value_box(ndarray arr, object loc): | |||
return util.get_value_1d(arr, i) | |||
|
|||
|
|||
# Add the min and max fields at the class level | |||
cdef int64_t _NS_LOWER_BOUND = -9223372036854775807LL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these constants different? (they are below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both are negative below which seems wrong. shouldn't these be each other's 2's complement? in which case _NS_LOWER_BOUND = -9223372036854775808
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the actual values are commented out....and somewhat platform dependent.....so not sure should be resetting these....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah i missed that. why not use LLONG_MAX/MIN? or do what @jreback suggested and use np.iinfo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this on Win7 as well and using np.iinfo(np.int64).min + 1 is not good because of the wraparound. The magic numbers supplied worked fine on both OSX and Windows that I've tested.
@SleepingPills maybe just define both of these as |
@SleepingPills can you define these as |
moving to 0.12 |
Sorry for the delay, I've been waylaid by some urgent stuff. I definitely wouldn't use np.iinfo(np.int64).min + 1 because of the wraparound. I'm not sure I understand the reasoning behind defining Timestamp.min as np.iinfo(np.int64).min. Wouldn't this simply mean that Timestamp.min == NaT? |
I mean defining the min num as also don't put the tests in a separate file; put in |
Even counting the fact that many other things, e.g. Timestamp.to_pydatetime() will behave really badly as a result? |
what do you mean |
Well:
We now get a completely wrong datetime object. Not counting the fact that we lose precision by the conversion, the way it would behave with the np.iinfo() solution is worse (IMO). |
sorry...yes you are right...the min datetime is a fixed value (and < np.iinfo(np.int64).min).....ok....fixed values are fine (I think wes avoided this whole wraparound issue on diff platforms by avoiding values that are too close to the min value).... pls move the tests to tseries/test/time_series..and can merge this |
Ok, I moved the tests and added an extra case for the datetime conversion roundtrip. |
perfect, could you add a release notes mention? (doc/sources/release.rst) and then squash down to a single commit? thanks |
Done. I thought I had pushed the changes to the docs already but turns out I had them on a different machine. How do I squash already pushed commits? |
fix any merge issues when done rebasing
use when done
will replace all existing commits with the new set generally on something like this is pretty short, can squash down to 1-2 |
related is #4065, if you would like to tackle would be appreciated (separate PR) |
Squashed |
thanks for the PR! merged |
Thanks for the assistance - I'll try to make it smoother going forward. |
closes #3863 by adding valid min and max fields to the Timestamp class.