Skip to content

BUG: Ambiguous time throws ambiguous error but then does not allow remediation with fold argument #44378

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

Closed
2 of 3 tasks
MataanAMZ opened this issue Nov 9, 2021 · 1 comment
Labels
Timezones Timezone data dtype Usage Question

Comments

@MataanAMZ
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
start_date = "2021-11-07T01:00:00"
tz = "America/Denver"
start_date = int(pd.Timestamp(start_date, tz=tz).timestamp(), fold=1)

Issue Description

The above code throws the following error.

ValueError: Cannot pass fold with possibly unambiguous input: int, float, numpy.datetime64, str, or timezone-aware datetime-like. Pass naive datetime-like or build Timestamp from components.

start_date with the tz is ambiguous, and it is a naive datetime-like.

Expected Behavior

Instead of this error, pd.Timestamp should fold the time to the second occurrence of Nov 7th 1am

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.8.9.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 49.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@MataanAMZ MataanAMZ added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 9, 2021
@MataanAMZ MataanAMZ changed the title BUG: BUG: Ambiguous time throws ambiguous error but then does not allow remediation with fold argument Nov 11, 2021
@mroeschke
Copy link
Member

The pd.Timestamp(start_date, tz=tz) call is raising the error (int doesn't accept a fold argument)

Moreover, fold is only supported if the Timestamp constructor is built from components (e.g. year=2021, month=11, etc)

We recommend instead using tz_localize for better localization support during ambiguous times (e.g. Timestamp(...).tz_localize(tz, ambiguous=True/False/...etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Timezones Timezone data dtype Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants