Skip to content

Issue passing a Timestamp to Series.between_time() #12680

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
SimonFransen opened this issue Mar 21, 2016 · 2 comments
Closed

Issue passing a Timestamp to Series.between_time() #12680

SimonFransen opened this issue Mar 21, 2016 · 2 comments
Labels
Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Usage Question

Comments

@SimonFransen
Copy link

Hi,

I have an issue with passing pandas.Timestamp objects as arguments to pandas.Series.between_time(start, end).

It appears that pandas.tseries.index.DatetimeIndex.indexer_between_time() tries to convert start_time and end_time arguments as strings.

The following lines give a temporary fix:

if not isinstance(start_time, Timestamp):
        start_time = to_time(start_time)
if not isinstance(end_time, Timestamp):
        end_time = to_time(end_time)

Thanks,
Simon

@jreback
Copy link
Contributor

jreback commented Mar 21, 2016

pls pd.show_versions()
pls show what the actual issue is via code sample

this was changed very explicitly for 0.18.0

@jreback jreback added Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Usage Question Duplicate Report Duplicate issue or pull request labels Mar 21, 2016
@jreback
Copy link
Contributor

jreback commented Mar 21, 2016

dupe of #11818, closed by #11832

In [12]: s = Series(np.arange(10),index=pd.date_range('20130101 09:00',periods=10,freq='H'))

In [13]: s
Out[13]: 
2013-01-01 09:00:00    0
2013-01-01 10:00:00    1
2013-01-01 11:00:00    2
2013-01-01 12:00:00    3
2013-01-01 13:00:00    4
2013-01-01 14:00:00    5
2013-01-01 15:00:00    6
2013-01-01 16:00:00    7
2013-01-01 17:00:00    8
2013-01-01 18:00:00    9
Freq: H, dtype: int64

In [14]: s.between_time(Timestamp('20130101 10:00'),Timestamp('20130101 14:00'))
ValueError: Cannot convert arg [Timestamp('2013-01-01 10:00:00')] to a time

In [15]: s.between_time('10:00','14:00')
Out[15]: 
2013-01-01 10:00:00    1
2013-01-01 11:00:00    2
2013-01-01 12:00:00    3
2013-01-01 13:00:00    4
2013-01-01 14:00:00    5
Freq: H, dtype: int64

@jreback jreback closed this as completed Mar 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants