Skip to content

BUG: FutureWarning for timezone-naive date time shouldn't be raised when indexing with a date #47882

Closed
@mmiller-max

Description

@mmiller-max

Pandas version checks

  • 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 main branch of pandas.

Reproducible Example

import pandas as pd
import datetime as dt
import pytz

index = pd.date_range(dt.datetime(2022,1,1), dt.datetime(2022,1,2), freq="h").tz_localize(pytz.timezone("Europe/Amsterdam"))
df = pd.DataFrame(index=index, data=range(0, len(index)))
df[dt.date(2022,1,1):dt.date(2022,1,2)]

# <stdin>:1: FutureWarning: Indexing a timezone-aware DatetimeIndex with a timezone-naive datetime is deprecated and will raise KeyError in a future version. Use a timezone-aware object instead.

Issue Description

A date cannot have a timezone, but the FutureWarning shown in the example is still raised because it is converted to a timezone-naive datetime here:

label = Timestamp(label).to_pydatetime()

Expected Behavior

No FutureWarning should be displayed as pandas supports slicing with dates, which cannot be timezone-aware, and therefore should ensure that the datetimes it creates are in the correct timezone.

Installed Versions

INSTALLED VERSIONS

commit : e8093ba
python : 3.9.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.104-linuxkit
Version : #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022
machine : aarch64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.3
numpy : 1.23.1
pytz : 2021.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 22.2.1
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 5.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TriageIssue that has not been reviewed by a pandas team memberdatetime.datestdlib datetime.date support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions