Error in slicing by datetime January 1, 2020 · Issue #33146 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd

dt = {'No': {pd.Timestamp('2020-01-01 00:00:00'): 123, pd.Timestamp('1900-01-01 00:00:00'): 345, pd.Timestamp('2017-04-18 00:00:00'): 946, pd.Timestamp('2020-01-02 00:00:00'): 940 }, 'CB': {pd.Timestamp('2020-01-01 00:00:00'): 'Sc', pd.Timestamp('1900-01-01 00:00:00'): 'Dr', pd.Timestamp('2017-04-18 00:00:00'): 'St', pd.Timestamp('2020-01-02 00:00:00'): 'Sc'}}

df = pd.DataFrame(dt)

only January 1 does not work properly

print(df['2019-12-31':]) print(df['2020-01-01':]) print(df['2020-01-02':])

All work properly

print(df[df.index >='2019-12-31']) print(df[df.index >='2020-01-01']) print(df[df.index >='2020-01-02'])

Problem description

Slicing by datetime index on January 1, 2020 returns the whole DataFrame

print(df['2020-01-01':])

Shows the whole DataFrame

Expected Output

only January 1 does not work properly

print(df['2020-01-01':])

incorrectly shows the whole DataFrame

2020-01-01 123 Sc
1900-01-01 345 Dr
2017-04-18 946 St
2020-01-02 946 Sc

print(df['2020-01-02':])

No CB
2020-01-02 946 Sc

All work properly

print(df[df.index >='2019-12-31'])

No CB
2020-01-01 123 Sc
2020-01-02 946 Sc

print(df[df.index >='2020-01-01'])

#works properly
No CB
2020-01-01 123 Sc
2020-01-02 946 Sc

print(df[df.index >='2020-01-02'])

2020-01-01 123 Sc
2020-01-02 946 Sc

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit : None
python : 3.7.2.final.0
python-bits : 32
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.3
numpy : 1.18.2
pytz : 2018.9
dateutil : 2.8.0
pip : 20.0.2
setuptools : 40.6.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 7.4.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.0.3
numexpr : None
odfpy : None
openpyxl : 3.0.2
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.2.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None