Skip to content

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

Closed
@jreback

Description

@jreback

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignConstructorsSeries/DataFrame/Index/pd.array ConstructorsError ReportingIncorrect or improved errors from pandasTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions