Skip to content
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/ENH: cleanup for Timedelta arithmetic #8884

Merged
merged 1 commit into from
Nov 26, 2014

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Nov 24, 2014

Fixes #8813
Fixes #5963
Fixes #5436

If the other argument has a dtype attribute, I assume that it is ndarray-like
and convert the Timedelta into a np.timedelta64 object. Alternatively, we
could just return NotImplemented and let the other type handle it, but this
has the bonus of making Timedelta compatible with ndarrays.

I also added a Timedelta.to_timedelta64() method to the public API. I
couldn't find a listing for Timedelta in the API docs -- we should probably
add that, right?

Next up would be a similar treatment for Timestamp.

CC @immerrr

@shoyer shoyer changed the title BUG/API: cleanup for Timedelta arithmetic BUG/ENH: cleanup for Timedelta arithmetic Nov 24, 2014
@jorisvandenbossche
Copy link
Member

Regarding to_timedelta64, I suppose it already exists as the asm8 attribute. But maybe adding such a method could be useful for visibility?

@jreback jreback added Bug Timedelta Timedelta data type labels Nov 24, 2014
@jreback jreback added this to the 0.15.2 milestone Nov 24, 2014
@jreback
Copy link
Contributor

jreback commented Nov 24, 2014

to_timedetta64() is fine (and adding to_datetime64() ok too). These are corresponding to to_timedelta()/to_datetime() and return the underlying object (and not the value, which is what asm8 does).

@jreback
Copy link
Contributor

jreback commented Nov 24, 2014

#5963 & #5436 might already be fixed / related. So might be able to just add in a couple of tests (or if they are enough there, lmk; e.g. pretty sure offsets already work).

@shoyer
Copy link
Member Author

shoyer commented Nov 24, 2014

@jreback Yep, those issues are indeed fixed. I added a bunch of tests and everything is passing now.

@@ -66,6 +66,11 @@ Enhancements
- Added support for ``utcfromtimestamp()``, ``fromtimestamp()``, and ``combine()`` on `Timestamp` class (:issue:`5351`).
- Added Google Analytics (`pandas.io.ga`) basic documentation (:issue:`8835`). See :ref:`here<remote_data.ga>`.
- Added flag ``order_categoricals`` to ``StataReader`` and ``read_stata`` to select whether to order imported categorical data (:issue:`8836`). See :ref:`here <io.stata-categorical>` for more information on importing categorical variables from Stata data files.
- ``Timedelta`` arithmetic returns ``NotImplemented`` in unknown cases, allowing extensions
by custom classes (:issue:`8813`).
- ``Timedelta`` now supports arithemtic with ``numpy.ndarray`` objects of the appropriate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add release notes for all issues fixed (or if 2 apply to the same one, pls list them there)

@jreback
Copy link
Contributor

jreback commented Nov 26, 2014

@shoyer looks good, some minor doc-like fixes.

FYI, you need to list each issue sepately with (closes/fixes) in order to have it close them when merged.

pls squash and ping when ready

@shoyer
Copy link
Member Author

shoyer commented Nov 26, 2014

#5963 was actually already fixed prior to this PR, but I'll note it anyways :).

Fixes GH8813
Fixes GH5963
Fixes GH5436

If the other argument has a dtype attribute, I assume that it is ndarray-like
and convert the `Timedelta` into a `np.timedelta64` object. Alternatively, we
could just return `NotImplemented` and let the other type handle it, but this
has the bonus of making `Timedelta` compatible with ndarrays.

I also added a `Timedelta.to_timedelta64()` method to the public API. I
couldn't find a listing for `Timedelta` in the API docs -- we should probably
add that, right?

Next up would be a similar treatment for `Timestamp`.
@shoyer
Copy link
Member Author

shoyer commented Nov 26, 2014

@jreback looks like we're ready.

jreback added a commit that referenced this pull request Nov 26, 2014
BUG/ENH: cleanup for Timedelta arithmetic
@jreback jreback merged commit 276462b into pandas-dev:master Nov 26, 2014
@jreback
Copy link
Contributor

jreback commented Nov 26, 2014

thanks

@shoyer shoyer deleted the fix-timedelta-math branch November 26, 2014 03:21
@@ -66,6 +66,11 @@ Enhancements
- Added support for ``utcfromtimestamp()``, ``fromtimestamp()``, and ``combine()`` on `Timestamp` class (:issue:`5351`).
- Added Google Analytics (`pandas.io.ga`) basic documentation (:issue:`8835`). See :ref:`here<remote_data.ga>`.
- Added flag ``order_categoricals`` to ``StataReader`` and ``read_stata`` to select whether to order imported categorical data (:issue:`8836`). See :ref:`here <io.stata-categorical>` for more information on importing categorical variables from Stata data files.
- ``Timedelta`` arithmetic returns ``NotImplemented`` in unknown cases, allowing extensions
by custom classes (:issue:`8813`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two spaces in the beginning of the line are missing (to align it with ```Time..`). But can be fixed later when doing a clean-up of the whatsnew file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixups here: ff0756f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
3 participants