Skip to content
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

Error in slicing by datetime January 1, 2020 #33146

Closed
ivan7707 opened this issue Mar 30, 2020 · 3 comments · Fixed by #38010
Closed

Error in slicing by datetime January 1, 2020 #33146

ivan7707 opened this issue Mar 30, 2020 · 3 comments · Fixed by #38010
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@ivan7707
Copy link

ivan7707 commented Mar 30, 2020

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

               No  CB

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'])

                 No  CB

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

@raziakhalidbutt
Copy link

it's working fine .

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

         No  CB

2020-01-01 123 Sc
2020-01-02 940 Sc

@jbrockmendel
Copy link
Member

I'm seeing an exception raised when slicing df["2019-12-31":] and the others working as expected. df.loc["2019-12-31":] works as expected

@jbrockmendel jbrockmendel added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Sep 2, 2020
@phofl
Copy link
Member

phofl commented Nov 22, 2020

Edit: Exception is no longer raised, but

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

still returns

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants