Skip to content

Conversation

@yrhooke
Copy link
Contributor

@yrhooke yrhooke commented Jul 7, 2018

xref #2141

Axis parameter added to between_time and at_time, defaults to index for DataFrame

@pep8speaks
Copy link

pep8speaks commented Jul 7, 2018

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

@jreback jreback added Enhancement Datetime Datetime data dtype labels Jul 7, 2018
@codecov
Copy link

codecov bot commented Jul 8, 2018

Codecov Report

Merging #21799 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21799      +/-   ##
==========================================
+ Coverage   92.24%   92.24%   +<.01%     
==========================================
  Files         161      161              
  Lines       51433    51441       +8     
==========================================
+ Hits        47446    47454       +8     
  Misses       3987     3987
Flag Coverage Δ
#multiple 90.64% <100%> (ø) ⬆️
#single 42.28% <7.69%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 96.84% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91d1c50...9ae360f. Read the comment docs.

Copy link
Contributor

@jreback jreback left a 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

Parameters
----------
time : datetime.time or string
axis : int or string axis name, optional
Copy link
Contributor

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)

end_time : datetime.time or string
include_start : boolean, default True
include_end : boolean, default True
axis : int or string axis name, optional
Copy link
Contributor

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]):
Copy link
Contributor

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):
Copy link
Contributor

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')
Copy link
Contributor

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)

@jreback
Copy link
Contributor

jreback commented Jul 8, 2018

a nice followup would be #2141 (separate PR after this one)

@yrhooke
Copy link
Contributor Author

yrhooke commented Jul 8, 2018

Alright, I'm on it.

- :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`)
Copy link
Contributor

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

try:
indexer = self.index.indexer_at_time(time, asof=asof)
return self._take(indexer)
index = self._get_axis(axis)
Copy link
Contributor

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)


try:
indexer = self.index.indexer_between_time(
index = self._get_axis(axis)
Copy link
Contributor

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)])
Copy link
Contributor

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', [
Copy link
Contributor

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

Copy link
Contributor

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

@yrhooke
Copy link
Contributor Author

yrhooke commented Jul 15, 2018

I hope it's alright now.

test_between_time_axis and test_between_time_axis_raises are trying to account for the scenarios where neither axis is a DatetimeIndex or that both are. If those are extraneous I can simplify them.

Also, should these tests be combined into the main test_between_time, test_at_time? I'm not sure what's preferred here.

Copy link
Contributor

@jreback jreback left a 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'])
Copy link
Contributor

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', [
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which new axis fixture?

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Member

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

def axis(request):

@jreback jreback added this to the 0.24.0 milestone Jul 20, 2018
@jreback
Copy link
Contributor

jreback commented Jul 25, 2018

can you rebase and add those tests, otherwise lgtm.

@jreback
Copy link
Contributor

jreback commented Aug 2, 2018

can you rebase and update

@yrhooke yrhooke force-pushed the between-time-axis branch from 3a35e7b to f637b24 Compare August 3, 2018 11:59
@yrhooke
Copy link
Contributor Author

yrhooke commented Aug 3, 2018

I rebased and updated the tests, they're kind of awkwardly built, I couldn't figure out what the axis fixture was.

@yrhooke yrhooke force-pushed the between-time-axis branch from dc9cf4f to 35b4b41 Compare August 9, 2018 13:30
- :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`)
Copy link
Contributor

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])
Copy link
Contributor

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', [
Copy link
Contributor

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'),
Copy link
Contributor

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

@jreback
Copy link
Contributor

jreback commented Sep 23, 2018

think this got lost, can you rebase

@jreback
Copy link
Contributor

jreback commented Oct 18, 2018

can you merge master

@jreback
Copy link
Contributor

jreback commented Nov 18, 2018

ok i rebased this.

@jreback jreback merged commit 97b612f into pandas-dev:master Nov 19, 2018
@jreback
Copy link
Contributor

jreback commented Nov 19, 2018

thanks @yrhooke

Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Datetime Datetime data dtype Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: add axis parameter to between_time, at_time

4 participants