Skip to content

BUG: truncate has wrong behavior when the Index has only one unique value #42365

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
3 tasks done
neelmraman opened this issue Jul 4, 2021 · 1 comment · Fixed by #42366
Closed
3 tasks done

BUG: truncate has wrong behavior when the Index has only one unique value #42365

neelmraman opened this issue Jul 4, 2021 · 1 comment · Fixed by #42366
Assignees
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@neelmraman
Copy link
Contributor

neelmraman commented Jul 4, 2021

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

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

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


Code Sample, a copy-pastable example

# Returns an empty Series/DataFrame when the one you pass in has length > 1 and an index with only one unique value
x = pd.Series(0, index=pd.date_range('2021-06-29', '2021-06-29')).repeat(5)
x.truncate('2021-06-28', '2021-07-01')

# If you add another unique index value, you get the expected behavior
x = pd.Series(0, index=pd.date_range('2021-06-29', '2021-06-29')).repeat(5)
y = pd.Series(0, index=pd.date_range('2021-06-01', '2021-06-01'))
x = x.append(y)
x.truncate('2021-06-28', '2021-07-01')

Problem description

I would expect truncate to not do any filtering in the first case given that all index values are between before and after. The fix is trivial, so I'll submit a PR.

Expected Output

2021-06-29    0
2021-06-29    0
2021-06-29    0
2021-06-29    0
2021-06-29    0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 7c48ff4
python : 3.9.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19043
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.2.5
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 52.0.0.post20210125
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : 2.7.3
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

@neelmraman neelmraman added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 4, 2021
@neelmraman
Copy link
Contributor Author

take

neelmraman added a commit to neelmraman/pandas that referenced this issue Jul 4, 2021
@jreback jreback added this to the 1.4 milestone Jul 4, 2021
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 4, 2021
neelmraman added a commit to neelmraman/pandas that referenced this issue Jul 4, 2021
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.

2 participants