-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: linearly spaced date_range (GH 20808) #20846
Conversation
exp = np.array(['2018-04-24T00:00:00', '2018-04-25T12:00:00', | ||
'2018-04-27T00:00:00'], dtype='datetime64[ns]') | ||
|
||
assert (rng == exp).all() |
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 can use tm.assert_numpy_array_equal
here
@@ -162,6 +162,21 @@ def test_date_range_ambiguous_arguments(self): | |||
with tm.assert_raises_regex(ValueError, msg): | |||
date_range(start, end, periods=10, freq='s') | |||
|
|||
def test_date_range_convenience_periods(self): |
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.
Could you also test this with the tz
arg specified? Would also be good to test a tz
where there is a day light savings transition between start
and end
.
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -450,6 +450,7 @@ Other Enhancements | |||
- Updated ``to_gbq`` and ``read_gbq`` signature and documentation to reflect changes from | |||
the Pandas-GBQ library version 0.4.0. Adds intersphinx mapping to Pandas-GBQ | |||
library. (:issue:`20564`) | |||
- :func:`pandas.core.indexes.datetimes.date_range` now returns a linearly spaced DatetimeIndex if ``start``, ``stop``, and ``periods`` are specified, but ``freq`` is not. (:issue:`20808`) |
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.
- func:`date_range` should suffice here
- DatetimeIndex --> ``DatetimeIndex``
pandas/core/indexes/datetimes.py
Outdated
|
||
# See https://github.com/pandas-dev/pandas/issues/20808 | ||
if freq is None and periods is not None and start is not None \ | ||
and end is not None: |
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.
A little bit cleaner to use if freq is None and com._all_not_none(periods, start, end):
pandas/core/indexes/datetimes.py
Outdated
raise TypeError(msg.format(periods=periods)) | ||
|
||
start = Timestamp(start) | ||
end = Timestamp(end) |
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.
start
and end
should be normalized if normalize=True
is passed to date_range
For consistency, it seems like this behavior should also be implemented for |
Codecov Report
@@ Coverage Diff @@
## master #20846 +/- ##
==========================================
+ Coverage 91.81% 91.81% +<.01%
==========================================
Files 153 153
Lines 49478 49484 +6
==========================================
+ Hits 45429 45435 +6
Misses 4049 4049
Continue to review full report at Codecov.
|
Hello @onnoeberhard! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on May 02, 2018 at 19:48 Hours UTC |
Alright, thank you for all the feedback. I have implemented almost everything mentioned, except for the implementation of a similar feature in the functions |
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.
also would be nice to add this to TDI
pandas/core/indexes/datetimes.py
Outdated
""" | ||
|
||
# See https://github.com/pandas-dev/pandas/issues/20808 |
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 needs to go in the DTI constructor itself. we already do some of this validation, it needs to fit in there. Further you don't need to worry about lots of other things that you are repeating, e.g. tz, which are already handled.
I have moved everything to the DTI constructor. With that I have removed the functionality to declare kwargs to |
Why do the tests time out? Is my code responsible for that? |
thank @onnoeberhard |
git diff upstream/master -u -- "*.py" | flake8 --diff