Skip to content

date_range treats '.5s' as '5s' #8419

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
keszybz opened this issue Sep 29, 2014 · 4 comments · Fixed by #14378
Closed

date_range treats '.5s' as '5s' #8419

keszybz opened this issue Sep 29, 2014 · 4 comments · Fixed by #14378
Labels
Enhancement Frequency DateOffsets Resample resample method
Milestone

Comments

@keszybz
Copy link

keszybz commented Sep 29, 2014

I'm new to pandas, so maybe I'm missing something, but I'd expected freq='.5s' to give me 500ms intervals, not 5s intervals:

pd.date_range(0, periods=5, freq='.5s')[1]
Timestamp('1970-01-01 00:00:05', offset='5S')
pd.date_range(0, periods=5, freq='500ms')[1]
Timestamp('1970-01-01 00:00:00.500000', offset='500L')
pd.version
'0.14.1'
import sys; sys.version
'3.4.1 (default, Jul 6 2014, 20:01:46) \n[GCC 4.9.0]'

Behaviour is the same under Python 2 and 3.

@jreback
Copy link
Contributor

jreback commented Sep 29, 2014

these don't take fractional units ATM (I don't think was ever implemented). I don't think very difficult to fix. welcome to have a pull-request.

@jreback jreback added this to the 0.16 milestone Sep 29, 2014
@jbradish
Copy link
Contributor

https://github.com/pydata/pandas/blob/master/pandas/tseries/frequencies.py#L97

I think this may have to do with the integer division when assigned values to a freq group. For example, if you also try .05s, it gets cut to 5S. I believe this is because of the (freq // 1000) operation used in grouping.

Someone else might be able to correct me or give additional insights.

Edit: jreback beat me to it. I might look into this tonight as it seems like it would be interesting, but simple. No promises though.

@jreback
Copy link
Contributor

jreback commented Sep 29, 2014

@jbradish sounds great!

basically you need to patch pandas.tseries.frequencies.to_offset() to handle.

@jreback jreback modified the milestones: 0.16, 0.15.1 Oct 7, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback added the Resample resample method label Jul 15, 2015
@sinhrks
Copy link
Member

sinhrks commented Aug 8, 2016

I think fix should be 2 parts:

1. offsets.Tick support fraction

Currently, Tick and DateOffset coerces input to int implicitly. I think Tick can return smaller tick to based on fraction, and DateOffset should explicitly raise.

pd.tseries.offsets.Hour(0.5)
# <0 * Hours>

pd.tseries.offsets.MonthEnd(0.5)
# <0 * MonthEnds>

2. to_offset support fraction

After Tick support fraction, it can be done with a slight change of regex and impl (related to #13930).

jisantuc added a commit to jisantuc/pandas that referenced this issue Oct 8, 2016
Passing `'0.5min'` as a frequency string should generate 30 second
intervals, rather than five minute intervals. By recursively increasing
resolution until one is found for which the frequency is an integer,
this commit ensures that that's the case for resolutions from days to
microseconds.

Fixes pandas-dev#8419
jisantuc added a commit to jisantuc/pandas that referenced this issue Oct 11, 2016
Passing `'0.5min'` as a frequency string should generate 30 second
intervals, rather than five minute intervals. By recursively increasing
resolution until one is found for which the frequency is an integer,
this commit ensures that that's the case for resolutions from days to
microseconds.

Fixes pandas-dev#8419
jisantuc added a commit to jisantuc/pandas that referenced this issue Oct 27, 2016
Passing `'0.5min'` as a frequency string should generate 30 second
intervals, rather than five minute intervals. By recursively increasing
resolution until one is found for which the frequency is an integer,
this commit ensures that that's the case for resolutions from days to
microseconds.

Fixes pandas-dev#8419
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.20.0, Next Major Release Dec 14, 2016
jorisvandenbossche pushed a commit that referenced this issue Dec 14, 2016
Passing `'0.5min'` as a frequency string should generate 30 second
intervals, rather than five minute intervals. By recursively increasing
resolution until one is found for which the frequency is an integer,
this commit ensures that that's the case for resolutions from days to
microseconds.

Fixes #8419
ischurov pushed a commit to ischurov/pandas that referenced this issue Dec 19, 2016
…4378)

Passing `'0.5min'` as a frequency string should generate 30 second
intervals, rather than five minute intervals. By recursively increasing
resolution until one is found for which the frequency is an integer,
this commit ensures that that's the case for resolutions from days to
microseconds.

Fixes pandas-dev#8419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Frequency DateOffsets Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants