Skip to content

Hitting AmbiguousTimeError when exiting DST using .loc #20724

Closed
@jackalack

Description

@jackalack

Code Sample, a copy-pastable example if possible

import pandas as pd
import arrow
import datetime
from dateutil import tz

test_time = arrow.get(datetime.datetime(2015,11,1), "US/Pacific").datetime
timestamps = [test_time + datetime.timedelta(seconds=i * 900) for i in range(16)]
my_series = pd.Series([0], index=[timestamps[0].replace(tzinfo=None)])
my_series = my_series.tz_localize(tz.gettz("US/Pacific"), ambiguous='infer')

for ts in timestamps:
    my_series.loc[ts] = 1

Problem description

I have a program that is running as a service and slowly adds timestamps to a pandas series. When running simulations, it always breaks when exiting DST.

INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.2.3
Cython: 0.24
numpy: 1.13.3
scipy: 0.18.1
pyarrow: None
xarray: None
IPython: 5.5.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.5.1
html5lib: 1.0b10
sqlalchemy: 1.2.4
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Testingpandas testing functions or related to the test suiteTimezonesTimezone data dtypegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions