-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH date_range accepts timedelta as freq #6318
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,7 @@ Enhancements | |
|
||
|
||
|
||
- ``pd.date_range`` accepts datetime and numpy timedeltas (:issue:`6307`). | ||
|
||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from datetime import datetime | ||
from datetime import datetime, timedelta | ||
from pandas.compat import range | ||
import pickle | ||
import nose | ||
|
@@ -370,6 +370,26 @@ def test_range_bug(self): | |
exp_values = [start + i * offset for i in range(5)] | ||
self.assert_numpy_array_equal(result, DatetimeIndex(exp_values)) | ||
|
||
def test_freq_timedelta_np(self): | ||
from pandas import _np_version_under1p7 | ||
if _np_version_under1p7: | ||
raise nose.SkipTest("date_range with freq timedelta " | ||
"not supported numpy < 1.7") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this may not need to be skipped |
||
|
||
from pandas.tseries.offsets import Nano, Micro, Second, Day | ||
|
||
nptd = np.timedelta64(1, 's') | ||
dti_n = date_range(start='2014-02-01', freq=nptd, periods=2) | ||
self.assertEqual(dti_n.freq, Second(1)) | ||
|
||
def test_freq_timedelta_dt(self): | ||
from pandas.tseries.offsets import Nano, Micro, Second, Day | ||
|
||
dttd = timedelta(1) | ||
us = Day(1).nanos / 1000 | ||
dti_d = date_range(start='2014-02-01', freq=dttd, periods=2) | ||
self.assertEqual(dti_d.freq, Micro(us)) | ||
|
||
def test_range_tz_pytz(self): | ||
# GH 2906 | ||
_skip_if_no_pytz() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is completely internal, yes? any reason to NOT always simplify? (e.g. in
to_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_offset uses offsets._delta_to_tick which also does this simplifying in a similar operation (delta to offset)...
...Ah ha, but
to_offset(an_offset)
atm is justan_offset
, are you suggesting it should return_simplify_offset(an_offset)
? This seems reasonable/in line with rest of function.