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

Comments

Projects
None yet
3 participants
@sinhrks
Copy link
Member

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 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

This comment has been minimized.

Copy link
Contributor

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 jbrockmendel added this to DatetimeIndex Bugs in DatetimeArray Refactor Nov 16, 2018

@jbrockmendel

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

@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.

@jbrockmendel jbrockmendel referenced this issue Dec 8, 2018

Merged

BUG: Assorted DatetimeIndex bugfixes #24157

1 of 1 task complete

@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Dec 13, 2018

@jbrockmendel jbrockmendel moved this from DTI/DTA Constructor Issues to Done in DatetimeArray Refactor Dec 15, 2018

@jbrockmendel jbrockmendel removed this from Done in DatetimeArray Refactor Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.