Skip to content
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

ERR: DatetimeIndex creation inconsistencies between list and ndarray #11587

Closed
sinhrks opened this issue Nov 13, 2015 · 2 comments · Fixed by #24157
Closed

ERR: DatetimeIndex creation inconsistencies between list and ndarray #11587

sinhrks opened this issue Nov 13, 2015 · 2 comments · Fixed by #24157
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Nov 13, 2015

Setting invalid freq against ndarray(dtype=int) should raise ValueError.

import numpy as np
import pandas as pd

pd.DatetimeIndex(np.array([pd.Timestamp('2011-01-01').value, pd.Timestamp('2011-01-03').value]), freq='D')
# ValueError: Inferred frequency None from passed dates does not conform to passed frequency D

There seems to be 2 issues:

1. invalid frequency may set if data is list

pd.DatetimeIndex([pd.Timestamp('2011-01-01').value, pd.Timestamp('2011-01-03').value], freq='D')
# DatetimeIndex(['2011-01-01', '2011-01-03'], dtype='datetime64[ns]', freq='D')

2. ndarray data may raise unclear error message

pd.DatetimeIndex(np.array([pd.tslib.iNaT, pd.Timestamp('2011-01-01').value]), freq='D')
# ValueError: NaTType does not support time
@sinhrks sinhrks added Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas labels Nov 13, 2015
@sinhrks sinhrks added this to the 0.17.1 milestone Nov 13, 2015
@sinhrks sinhrks changed the title BUG: DatetimeIndex creation inconsistencies between list and ndarray ERR: DatetimeIndex creation inconsistencies between list and ndarray Nov 13, 2015
@jreback
Copy link
Contributor

jreback commented Nov 13, 2015

[1] is correct.

In [8]: pd.DatetimeIndex([pd.Timestamp('2011-01-01').value, pd.Timestamp('2011-01-03').value], freq='D')
Out[8]: DatetimeIndex(['2011-01-01', '2011-01-03'], dtype='datetime64[ns]', freq='D')

In [9]: pd.DatetimeIndex([pd.Timestamp('2011-01-01').value, pd.Timestamp('2011-01-03').value], freq='D').inferred_freq

you can set any freq you want on a DatetimeIndex. It doesn't infer in this case because its too short.

@jreback jreback modified the milestones: Next Major Release, 0.17.1 Nov 13, 2015
@jbrockmendel
Copy link
Member

@sinhrks the list and ndarray behavior now match. Can you confirm that part 1 of the issue is resolved. I'll take a look at the second part.

@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants