Skip to content

Odd behavior with floats and dateranges #14377

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
jisantuc opened this issue Oct 7, 2016 · 2 comments
Closed

Odd behavior with floats and dateranges #14377

jisantuc opened this issue Oct 7, 2016 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Frequency DateOffsets

Comments

@jisantuc
Copy link
Contributor

jisantuc commented Oct 7, 2016

When creating a daterange with a decimal number of minutes, pandas truncates everything before the decimal point. This leads to odd results e.g. if you're expecting to generate something every half minute and instead end up with something every 5 minutes, and even odder results if you have a float that is a whole number.

A less contrived example is if pandas is used to process the results of some API call where you don't know what unit you'll have to go to to get to a whole number. It would be safe, I guess, to convert everything to nanoseconds, but not especially readable.

A small, complete example of the issue

>>> import pandas as pd
>>> pd.date_range(end='2016-10-07T21:08:58.490180', periods=3, freq='0.5min')
DatetimeIndex(['2016-10-07 20:58:58.490180', '2016-10-07 21:03:58.490180',
               '2016-10-07 21:08:58.490180'],
              dtype='datetime64[ns]', freq='5T')
>>> pd.date_range(end='2016-10-07T21:08:58.490180', periods=3, freq='10080.0min')
DatetimeIndex([], dtype='datetime64[ns]', freq='0T')

Expected Output

For the first example:
DatetimeIndex(['2016-10-07 21:07:58.490180', '2016-10-07 21:08:28.490180', '2016-10-07 21:08:58.490180'], dtype='datetime64[ns]', freq='30S')

For the second:
DatetimeIndex(['2016-09-23 21:08:58.490180', '2016-09-30 21:08:58.490180', '2016-10-07 21:08:58.490180'], dtype='datetime64[ns]', freq='10080T')

Output of pd.show_versions()

## INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-38-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.1
pip: 1.5.4
setuptools: 26.0.0
Cython: None
numpy: 1.11.1
scipy: 0.17.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.3.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.15
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: 2.41.0
pandas_datareader: None

@jisantuc
Copy link
Contributor Author

jisantuc commented Oct 7, 2016

After following traceback I don't think this would be hard to fix, so I'm happy to do that if it's agreed that what I expected is a reasonable expectation.

@jreback
Copy link
Contributor

jreback commented Oct 7, 2016

this is a duplicate of #8419

welcome a fix for that (you can use your example and the other as examples).

@jreback jreback closed this as completed Oct 7, 2016
@jreback jreback added Frequency DateOffsets Duplicate Report Duplicate issue or pull request labels Oct 7, 2016
@jreback jreback added this to the No action milestone Oct 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Frequency DateOffsets
Projects
None yet
Development

No branches or pull requests

2 participants