-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: Adding origin parameter in pd.to_datetime #11470
ENH: Adding origin parameter in pd.to_datetime #11470
Conversation
julian
to to_datetime
julian
to to_datetime
tests! |
On it. Any boundary conditions that I must take into consideration? |
what do you mean? |
also this would need to be added in Timestamp as that accepts a unit as well |
julian
to to_datetime
Apologies for the late reply. I am not able to understand which file to edit for Timestamp. Kindly guide, @jreback? |
Thanks @jreback. Will go through the file asap :-) |
Hi, I am bit confused regarding the implementation. As far as I could understand, following might help. Kindly correct me if I am wrong.
Does it seem okay, @jreback? |
@sumitbinnani this should be implemented in |
this needs tests |
see #11745; let's call this |
Have been a bit occupied for last a few weeks owing to applications and submission deadlines. Will make the necessary changes for #11745 asap. Facing a bit difficulty writing test cases (going through documentations and will mostly be done by this weekend). |
Have changed the definition of
Should I remove the changes made to the class |
@sumitbinnani yes, remove the original |
86681d2
to
45037a8
Compare
1deddb0
to
86681d2
Compare
Hi @jreback, Have made the changes as followed:
Let me know if any additional changes are required. |
@@ -743,6 +743,22 @@ def test_to_datetime_unit(self): | |||
result = to_datetime(s,unit='s') | |||
expected = Series([ Timestamp('2013-06-09 02:42:28') + timedelta(seconds=t) for t in range(20) ] + [NaT]) | |||
assert_series_equal(result,expected) | |||
|
|||
def test_to_datetime_origin(self): | |||
# for origin as julian |
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.
add the issue number as a comment
pls add whatsnew note in Enhancements for 0.18.0 |
0 1960-01-01 | ||
1 1960-01-02 | ||
... | ||
98 1960-04-08 |
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 output here of the example does not yet match the example code
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.
Opps. My Bad. Updated the documentation with proper output.
Rectified mistake in documentation.
Have rectified the mistake in example. Unsure about how to proceed for the aforementioned invalid-origin :-( |
I think this is fine for now. We could make this happen, but the code then gets convoluted, but it is so rare as not to be important. I would just assert that this example raises. |
@@ -24,6 +24,16 @@ New features | |||
|
|||
.. _whatsnew_0190.dev_api: | |||
|
|||
to_datetime can be used with Offset |
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.
to_datetime has gained an origin kwarg
.
don't call this Offset
which is a very specific meaning
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.
in the doc-string this is a 'reference date', so I would use that here.
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.
Done.
can you rebase / update? |
763a620
to
ffd9b28
Compare
a99fdb3
to
4396d81
Compare
@sumitbinnani Can you move the whatsnew notice to the v0.20.0.txt file? As 0.19.0 has been releases in the meantime (also, all the other changes in the 0.19.0.txt file should not be included in here) |
@jorisvandenbossche The v0.19.0 had been reverted to the master. Changes added to v0.20.0. |
Some examples that now go wrong:
So in EDIT: regarding |
@sumitbinnani what I think you could do to simplify the code (having all handling of origin in one place) is the following: start with processing the So something like (pseudocode)
A way to deal with the out of bounds origin would be to use |
can you rebase / update according to comments |
@sumitbinnani I know this has been open a long time. can you rebase and we'll see if can get it in? pls change release note to 0.20.0 |
@jreback Sure. Would go through the code this weekend and rebase :-) |
@jreback There are quite a many changes. I would start clean and update asap. Sorry for the delay. |
@sumitbinnani Useful feature so would be good to get this in |
return _convert_listlike(arg, box, format, name=arg.name) | ||
elif is_list_like(arg): | ||
return _convert_listlike(arg, box, format) | ||
def intermediate_result(arg): |
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.
Is there some reason this is a function? It looks like it should just be an if, else if, else
Define reference date. The numeric values would be parsed as number | ||
of units (defined by `unit`) since this reference date. | ||
|
||
- If 'epoch', origin is set to 1970-01-01. |
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.
You could consider other standard offsets: excel
, Jan 0 1900, stata
Jan 0, 1960, matlab
, Jan 0, 0000? Just an idea
superseded by #15828 @sumitbinnani I rebase and updated your PR. thanks! |
closes #11276 closes #11745 superseded #11470 Author: Jeff Reback <jeff@reback.net> Author: Sumit Binnani <sumit.binnani@gmail.com> Closes #15828 from jreback/datetime-unit and squashes the following commits: ebb4acd [Jeff Reback] doc fixes & cleanup 209591a [Jeff Reback] bug fix 56663a5 [Jeff Reback] add Timedelta floordiv ops a24e88c [Jeff Reback] rename epoch -> unix 6a8a779 [Jeff Reback] update docs / tests ad7356e [Sumit Binnani] BUG: Series creation with datetime64 with non-ns unit as object dtype
Fixes #11276
Fixes #11745