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

ERR: better error message on non-sorted input with .truncate #17935

Closed
jreback opened this issue Oct 21, 2017 · 2 comments · Fixed by #17984
Closed

ERR: better error message on non-sorted input with .truncate #17935

jreback opened this issue Oct 21, 2017 · 2 comments · Fixed by #17984
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Oct 21, 2017

xref #17295

This is correct, but since the doc-string says sorted, we should check this and give a nicer message. (not that should check both .is_monotonic_increasing and decreasing cases, and confirm that the before/after match)

In [8]: rng2 = pd.date_range('2011-01-01', '2012-01-01', freq='W')
   ...: ts2 = pd.Series(np.random.randn(len(rng2)), index=rng2)

In [9]: ts2.truncate(before='2011-11', after='2011-12')
Out[9]: 
2011-11-06    0.144986
2011-11-13   -1.823425
2011-11-20    1.742315
2011-11-27    0.311337
Freq: W-SUN, dtype: float64

In [10]: ts2.sort_values(ascending=False).truncate(before='2011-11', after='2011-12')
KeyError: Timestamp('2011-11-01 00:00:00')
@jreback jreback added Difficulty Novice Error Reporting Incorrect or improved errors from pandas Datetime Datetime data dtype labels Oct 21, 2017
@jreback jreback added this to the Next Major Release milestone Oct 21, 2017
@jreback
Copy link
Contributor Author

jreback commented Oct 21, 2017

cc @reidy-p

@reidy-p
Copy link
Contributor

reidy-p commented Oct 21, 2017

@jreback thanks, I'll take a look.

@jreback jreback modified the milestones: Next Major Release, 0.21.1, 0.22.0 Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants