-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: TimeStamp looses frequency info on arithmetic ops #4547
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
Comments
You are selecting a single timestamp out, by definition it does not have a frequency; try selecting with a slice (even a len 1 slice)
|
Thnx for the reply. I understand what you mean. However, Timestamp seems to have a frequency. Also, if you ask me, it makes sense to increment timestamps with +1 and -1, since that allows you to easily index DatetimeIndex objects |
what does |
ts1-1-1=(ts1-1)-1 |
A single key selection simply has different semantics (across all of pandas), rather than a slice, The following does what you want (note that I leave the index as is), then select the element at the end
|
Thnx for the solution, I did something like to as a "dirty hack" to fix the code. However, still, if TimeStamp has an attribute freq, as it does. See for example: The whole purpose of have have timestamps with a frequency attribute is to use incremental operators on them right? |
Ok this is a bug (but not where I thought); The timestamp has the freq when its taken from the datetimeindex (its not printing it, which may be a separate issue), but its there
The sub operation on a Timestamp is treated correctly, but the new freq is not propogated to the new date
|
I completely agree! :) |
this is a very straightforward change in up for a PR? |
Good to hear that the change is straightforward! What's a PR? :) |
PR == pull request |
have a look here http://pandas.pydata.org/developers.html |
Thanks for submitting your pull request so quickly. If I understand you correctly, you want me to pull you pull request and then we can discuss whether the issue is solved right? |
that is all fine |
Oh, i just reread your comment. I would like you to actually do the patch (by submitting a pull request), and add tests as needed. It helps you understand the codebase and even how to use pandas better! |
Sure, I'll try. I think it will work out, hardest part will be getting used to the conventions and git interface ;-) |
i'm happy to help you with |
also see #3156 for some tools that will make git/github integration easier, esp. |
@Martin31415926 doing a PR for this? |
Hi jreback, I would like too... but I'm finishing my PhD thesis at the moment, so unfortunately I can't make time for it at the moment. Sorry :( |
You can assign this to me - I'm in this code already looking at another minor Timestamp addition/subtraction issue. (which I haven't created an issue for, I figured I would just submit the PR) |
gr8! thanks @rosnfeld |
Design question: what if somebody adds/subtracts a timedelta (or timedelta64) that is not in keeping with the Timestamp's frequency? timestamp = date_range('2014-03-05', periods=10, freq='D')[0]
new_timestamp = timestamp + datetime.timedelta(seconds=1) Now it's a little weird to "mix" new_timestamp and timestamp, as they are no longer "aligned". One could say they have the same frequency or period, but different "phase". Maybe we just copy the frequency over to the new object and trust that users know what they are doing? Or we don't support copying frequency with anything but integer addition/subtraction. I'm inclined to do the former. I feel we can do better than just not copying it, but doing any checking is going to be expensive; I'm not aware of a way to check that a new timestamp "fits" a given frequency-driven series of Timestamps other than by constructing something like a DatetimeIndex and testing for inclusion. |
BUG: preserve frequency across Timestamp addition/subtraction (#4547)
Running the follow code generates an error using pandas 0.11 (with winpython 2.7.5.2 64 bit):
import pandas as pd
ts1=pd.date_range('1/1/2000',periods=1,freq='Q')[0]
ts1-1-1
Error:
Traceback (most recent call last):
File "", line 1, in
File "tslib.pyx", line 566, in pandas.tslib._Timestamp.sub (pandas\tslib.c:10775)
File "tslib.pyx", line 550, in pandas.tslib._Timestamp.add (pandas\tslib.c:10477)
ValueError: Cannot add integral value to Timestamp without offset.
Reason:
ts1.freq has value:
1 QuarterEnd: startingMonth=12, kwds={'startingMonth': 12}, offset=3 MonthEnds
but
(ts1-1).freq has no value
The text was updated successfully, but these errors were encountered: