-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: between_time, at_time accept axis parameter #21799
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
Conversation
|
Hello @yrhooke! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 09, 2018 at 13:30 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #21799 +/- ##
==========================================
+ Coverage 92.24% 92.24% +<.01%
==========================================
Files 161 161
Lines 51433 51441 +8
==========================================
+ Hits 47446 47454 +8
Misses 3987 3987
Continue to review full report at Codecov.
|
jreback
left a comment
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.
can you add a whatsnew in other enhancements for 0.24.0
pandas/core/generic.py
Outdated
| Parameters | ||
| ---------- | ||
| time : datetime.time or string | ||
| axis : int or string axis name, optional |
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.
can you add a versionadded 0.24.0 here (and other new kwargs)
pandas/core/generic.py
Outdated
| end_time : datetime.time or string | ||
| include_start : boolean, default True | ||
| include_end : boolean, default True | ||
| axis : int or string axis name, optional |
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.
same
| stime, etime = ('08:00:00', '09:00:00') | ||
| dimn = (len(rng), len(rng)) | ||
| exp_len = 7 | ||
| for time_index, time_col in product([True, False], [True, False]): |
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.
can you parametrize this test instead of using a loop
| with pytest.raises(TypeError): # index is not a DatetimeIndex | ||
| df.at_time('00:00') | ||
|
|
||
| def test_at_time_axis(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.
you can parametrize if you want
| assert len(ts.between_time(*time_string)) == expected_length | ||
|
|
||
| def test_between_time_axis(self): | ||
| rng = date_range('1/1/2000', periods=100, freq='10min') |
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.
can you add the issue number as a comment (to all new tests)
|
a nice followup would be #2141 (separate PR after this one) |
|
Alright, I'm on it. |
doc/source/whatsnew/v0.24.0.txt
Outdated
| - :meth:`Series.nlargest`, :meth:`Series.nsmallest`, :meth:`DataFrame.nlargest`, and :meth:`DataFrame.nsmallest` now accept the value ``"all"`` for the ``keep`` argument. This keeps all ties for the nth largest/smallest value (:issue:`16818`) | ||
| - :class:`IntervalIndex` has gained the :meth:`~IntervalIndex.set_closed` method to change the existing ``closed`` value (:issue:`21670`) | ||
| - :func:`~DataFrame.to_csv` and :func:`~DataFrame.to_json` now support ``compression='infer'`` to infer compression based on filename (:issue:`15008`) | ||
| - :func:`between_time` and :func:`at_time` now support an axis parameter (:issue: `8839`) |
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.
can you use double backticks around axis
pandas/core/generic.py
Outdated
| try: | ||
| indexer = self.index.indexer_at_time(time, asof=asof) | ||
| return self._take(indexer) | ||
| index = self._get_axis(axis) |
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.
can you move the _get_axis out of the try/except (and the _take)
pandas/core/generic.py
Outdated
|
|
||
| try: | ||
| indexer = self.index.indexer_between_time( | ||
| index = self._get_axis(axis) |
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.
same comment as above
| df.at_time('00:00') | ||
|
|
||
| @pytest.mark.parametrize('time_axis', [ | ||
| (False, False), (True, False), (False, True), (True, True)]) |
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.
hmm this is an odd way to parameterize, can you just use axis as the argument?
| with pytest.raises(TypeError): # index is not a DatetimeIndex | ||
| df.between_time(start_time='00:00', end_time='12:00') | ||
|
|
||
| @pytest.mark.parametrize('time_axis', [ |
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.
same this is very hard to read
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 make the error case a separate test, which makes both tests much simpler
|
I hope it's alright now.
Also, should these tests be combined into the main |
jreback
left a comment
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.
small comments. pls rebase and ping on green.
| with pytest.raises(TypeError): # index is not a DatetimeIndex | ||
| df.at_time('00:00') | ||
|
|
||
| @pytest.mark.parametrize('axis', ['index', 'columns']) |
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.
test for 0, 1 as well
| with pytest.raises(TypeError): # index is not a DatetimeIndex | ||
| df.between_time(start_time='00:00', end_time='12:00') | ||
|
|
||
| @pytest.mark.parametrize('axis', [ |
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 test for 0, 1
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 new axis fixture will handle this, can you use that
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.
which new axis fixture?
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.
rebase in master and axis is available
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.
why is this not just using the axis fixture?
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.
I couldn't figure out what the axis fixture is. Is there documentation about this?
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.
Here's the location of it. It just supplies the various arguments that are typically valid for an axis parameter
Line 65 in c04b773
| def axis(request): |
|
can you rebase and add those tests, otherwise lgtm. |
|
can you rebase and update |
3a35e7b to
f637b24
Compare
|
I rebased and updated the tests, they're kind of awkwardly built, I couldn't figure out what the axis fixture was. |
dc9cf4f to
35b4b41
Compare
doc/source/whatsnew/v0.24.0.txt
Outdated
| - :func:`to_timedelta` now supports iso-formated timedelta strings (:issue:`21877`) | ||
| - :class:`Series` and :class:`DataFrame` now support :class:`Iterable` in constructor (:issue:`2193`) | ||
| - :class:`DatetimeIndex` gained :attr:`DatetimeIndex.timetz` attribute. Returns local time with timezone information. (:issue:`21358`) | ||
| - :func:`~DataFrame.to_csv` and :func:`~DataFrame.to_json` now support ``compression='infer'`` to infer compression based on filename (:issue:`15008`) |
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.
looks like you picked up something extra here
| with pytest.raises(TypeError): # index is not a DatetimeIndex | ||
| df.at_time('00:00') | ||
|
|
||
| @pytest.mark.parametrize('axis', ['index', 'columns', 0, 1]) |
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.
just remove the paramerize, the axis is already defined
| with pytest.raises(TypeError): # index is not a DatetimeIndex | ||
| df.between_time(start_time='00:00', end_time='12:00') | ||
|
|
||
| @pytest.mark.parametrize('axis', [ |
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.
why is this not just using the axis fixture?
| assert len(selected) == exp_len | ||
|
|
||
| @pytest.mark.parametrize('axis', [ | ||
| (), ('index',), ('columns',), ('index', 'columns'), |
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.
same, this is very werid
|
think this got lost, can you rebase |
|
can you merge master |
|
ok i rebased this. |
|
thanks @yrhooke |
xref #2141
Axis parameter added to between_time and at_time, defaults to index for DataFrame