-
-
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: between_time, at_time accept axis parameter #21799
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.
|
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
@@ -6772,6 +6772,7 @@ def at_time(self, time, asof=False): | |||
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
@@ -6826,6 +6832,7 @@ def between_time(self, start_time, end_time, include_start=True, | |||
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
@@ -640,6 +640,22 @@ def test_at_time_raises(self): | |||
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
@@ -817,6 +817,16 @@ def test_between_time_formats(self): | |||
for time_string in strings: | |||
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
@@ -114,6 +114,7 @@ Other Enhancements | |||
- :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
@@ -640,6 +640,27 @@ def test_at_time_raises(self): | |||
with pytest.raises(TypeError): # index is not a DatetimeIndex | |||
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?
@@ -706,6 +727,40 @@ def test_between_time_raises(self): | |||
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 |
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.
@@ -640,6 +640,23 @@ def test_at_time_raises(self): | |||
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
@@ -706,6 +723,44 @@ def test_between_time_raises(self): | |||
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
@@ -182,6 +182,9 @@ Other Enhancements | |||
- :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
@@ -640,6 +640,23 @@ def test_at_time_raises(self): | |||
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
@@ -706,6 +723,44 @@ def test_between_time_raises(self): | |||
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 |
…fixed * upstream/master: (46 commits) DEPS: bump xlrd min version to 1.0.0 (pandas-dev#23774) BUG: Don't warn if default conflicts with dialect (pandas-dev#23775) BUG: Fixing memory leaks in read_csv (pandas-dev#23072) TST: Extend datetime64 arith tests to array classes, fix several broken cases (pandas-dev#23771) STYLE: Specify bare exceptions in pandas/tests (pandas-dev#23370) ENH: between_time, at_time accept axis parameter (pandas-dev#21799) PERF: Use is_utc check to improve performance of dateutil UTC in DatetimeIndex methods (pandas-dev#23772) CLN: io/formats/html.py: refactor (pandas-dev#22726) API: Make Categorical.searchsorted returns a scalar when supplied a scalar (pandas-dev#23466) TST: Add test case for GH14080 for overflow exception (pandas-dev#23762) BUG: Don't extract header names if none specified (pandas-dev#23703) BUG: Index.str.partition not nan-safe (pandas-dev#23558) (pandas-dev#23618) DEPR: tz_convert in the Timestamp constructor (pandas-dev#23621) PERF: Datetime/Timestamp.normalize for timezone naive datetimes (pandas-dev#23634) TST: Use new arithmetic fixtures, parametrize many more tests (pandas-dev#23757) REF/TST: Add more pytest idiom to parsers tests (pandas-dev#23761) DOC: Add ignore-deprecate argument to validate_docstrings.py (pandas-dev#23650) ENH: update pandas-gbq to 0.8.0, adds credentials arg (pandas-dev#23662) DOC: Improve error message to show correct order (pandas-dev#23652) ENH: Improve error message for empty object array (pandas-dev#23718) ...
xref #2141
Axis parameter added to between_time and at_time, defaults to index for DataFrame