Skip to content

BUG/API: Timestamp(naive_str, tz=tz) vs Timestamp(naive_str).tz_localize(tz)  #55657

@jbrockmendel

Description

@jbrockmendel
dtstr = '11/06/2011 01:00'
tz = "US/Eastern"

>>> pd.Timestamp(dtstr, tz=tz)
Timestamp('2011-11-06 01:00:00-0500', tz='US/Eastern')

>>> pd.Timestamp(dtstr).tz_localize(tz)
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 2011-11-06 01:00:00, try using the 'ambiguous' argument

I expected these to be equivalent. Am I wrong to expect that?

Looks like the constructor version goes through _localize_pydatetime (then pytz's tz.localize) instead of Timestamp.tz_localize which apparently doesn't find this case ambiguous.

Update: passing is_dst=None to tz.localize in _localize_pydatetime causes the constructor version to raise like I expected.

Update 2: passing is_dst=None as above breaks two tests in the test suite: test_dti_tz_localize_ambiguous_infer and test_fallback_singular

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team memberTimestamppd.Timestamp and associated methods

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions