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: stricter checks on Index construction when tz is passed #14093

Closed
jreback opened this issue Aug 26, 2016 · 4 comments · Fixed by #38597
Closed

ERR: stricter checks on Index construction when tz is passed #14093

jreback opened this issue Aug 26, 2016 · 4 comments · Fixed by #38597
Labels
API Design Constructors Series/DataFrame/Index/pd.array Constructors Error Reporting Incorrect or improved errors from pandas Timezones Timezone data dtype
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Aug 26, 2016

from comment on #13981

In [1]: pd.Index([datetime.datetime(2012,1,1), datetime.datetime(2012,1, 2)], tz="Europe/Brussels")
Out[1]: DatetimeIndex(['2012-01-01 00:00:00+01:00', '2012-01-02 00:00:00+01:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)

In [2]: pd.Index([1, 2], tz="Europe/Brussels")
Out[2]: DatetimeIndex(['1970-01-01 00:00:00+01:00', '1970-01-01 00:00:00+01:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)

In [3]: pd.Index(['20120102', '20120103'], tz="Europe/Brussels")
Out[3]: DatetimeIndex(['2012-01-02 00:00:00+01:00', '2012-01-03 00:00:00+01:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)

[1] is fine/expected
[2] should be disallowed (e.g. integer construction)
[3] is ok, maybe should disallow to be consistent.

I am not sure what this would break. But we don't necessarily want to force datetime construction on a generic Index (as opposed to using .to_datetime or a constructor, e.g. pd.date_range). This is a bit too much inference.

So the rule would be that it has to be actual datetimes/Timestamps, if tz is provided (which is a form of dtype).

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Timezones Timezone data dtype Difficulty Intermediate labels Aug 26, 2016
@jreback jreback added this to the Next Major Release milestone Aug 26, 2016
@jreback
Copy link
Contributor Author

jreback commented Aug 26, 2016

@jorisvandenbossche
Copy link
Member

+1 on disallowing [1] and [2].
I personally also do not really like that you can pass tz in Index (as this is not documented), but it's ok that that returns a DatetimeIndex

@sinhrks
Copy link
Member

sinhrks commented Aug 29, 2016

I think passing tz to normal Index may better to be deprecated as it is ambiguous (so disallow [1], [2] and [3]).

I assume the behavior was a workaround to keep DatetimeIndex as a MultiIndex level (solved after #13981).

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.20.0, Next Major Release Aug 29, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
@jbrockmendel jbrockmendel added the Constructors Series/DataFrame/Index/pd.array Constructors label Jul 23, 2019
@jbrockmendel
Copy link
Member

looks like we have 21 tests that pass tz kwarg to Index

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Constructors Series/DataFrame/Index/pd.array Constructors Error Reporting Incorrect or improved errors from pandas Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants