-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
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 datetime
import pandas as pd
import pytz
rng = pd.date_range(start="1/1/2000", periods=1, tz="Etc/GMT+8")
ts = pd.DataFrame(list(range(len(rng))), index=rng)
midnight_gmt_7 = datetime.time(tzinfo=pytz.timezone("Etc/GMT+7"))
print(ts.between_time(midnight_gmt_7, midnight_gmt_7, inclusive='both'))
Issue Description
between_time
ignores the timezone info of start_time
and end_time
. In the example above, it counts midnight in GMT + 7 as equal to midnight in GMT + 8. Note also that ts.at_time(midnight_gmt_7)
correctly gives an empty list .
Expected Behavior
between_time
should account for timezone, as at_time
does here:
pandas/pandas/core/indexes/datetimes.py
Lines 723 to 726 in a063af0
if time.tzinfo: | |
if self.tz is None: | |
raise ValueError("Index must be timezone aware.") | |
time_micros = self.tz_convert(time.tzinfo)._get_time_micros() |
Instead, betwen_time
just converts to micros without looking at time zone:
pandas/pandas/core/indexes/datetimes.py
Lines 756 to 757 in a063af0
start_time = to_time(start_time) | |
end_time = to_time(end_time) |
Installed Versions
INSTALLED VERSIONS
commit : 7cb7592
python : 3.10.4.final.0
python-bits : 64
OS : Darwin
OS-release : 21.5.0
Version : Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.0.dev0+1147.g7cb7592523
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.1.2
Cython : 0.29.32
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.5.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : None
qtpy : None
pyqt5 : None