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

Closed
keszybz opened this Issue Sep 29, 2014 · 4 comments

Comments

Projects
None yet
5 participants

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.

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 added this to the 0.16 milestone Sep 29, 2014

Contributor

jbradish commented Sep 29, 2014

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.

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 milestone: 0.16, 0.15.1 Oct 7, 2014

@jreback jreback modified the milestone: 0.16.0, Next Major Release Mar 6, 2015

jreback added the Resample label Jul 15, 2015

jreback referenced this issue Aug 8, 2016

Closed

BUG: freqstr may be parsed incorrectly #13930

3 of 3 tasks complete
Member

sinhrks commented Aug 8, 2016 edited

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 jisantuc added a commit to jisantuc/pandas that referenced this issue Oct 8, 2016

@jisantuc jisantuc Convert float freqstrs to ints at finer resolution
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
b869a30

@jisantuc jisantuc added a commit to jisantuc/pandas that referenced this issue Oct 11, 2016

@jisantuc jisantuc Convert float freqstrs to ints at finer resolution
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
33664a6

@jisantuc jisantuc added a commit to jisantuc/pandas that referenced this issue Oct 27, 2016

@jisantuc jisantuc Convert float freqstrs to ints at finer resolution
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
47723c3

@jorisvandenbossche jorisvandenbossche added a commit that referenced this issue Dec 14, 2016

@jisantuc @jorisvandenbossche jisantuc + jorisvandenbossche BUG: Convert float freqstrs to ints at finer resolution (#14378)
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
8b89ece

@ischurov ischurov added a commit to ischurov/pandas that referenced this issue Dec 19, 2016

@jisantuc @ischurov jisantuc + ischurov BUG: Convert float freqstrs to ints at finer resolution (#14378)
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
c386806
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment