File tree 3 files changed +13
-2
lines changed
3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ Categorical
48
48
49
49
**Indexing **
50
50
51
- -
51
+ - Bug in :meth: ` Series.truncate ` when trying to truncate a single-element series ( :issue: ` 35544 `)
52
52
53
53
**DataFrame **
54
54
- Bug in :class: `DataFrame ` constructor failing to raise ``ValueError `` in some cases when data and index have mismatched lengths (:issue: `33437 `)
Original file line number Diff line number Diff line change @@ -9405,7 +9405,7 @@ def truncate(
9405
9405
if before > after :
9406
9406
raise ValueError (f"Truncate: { after } must be after { before } " )
9407
9407
9408
- if ax .is_monotonic_decreasing :
9408
+ if len ( ax ) > 1 and ax .is_monotonic_decreasing :
9409
9409
before , after = after , before
9410
9410
9411
9411
slicer = [slice (None , None )] * self ._AXIS_LEN
Original file line number Diff line number Diff line change @@ -141,3 +141,14 @@ def test_truncate_multiindex(self):
141
141
expected = df .col
142
142
143
143
tm .assert_series_equal (result , expected )
144
+
145
+ def test_truncate_one_element_series (self ):
146
+ # GH 35544
147
+ series = pd .Series ([0.1 ], index = pd .DatetimeIndex (["2020-08-04" ]))
148
+ before = pd .Timestamp ("2020-08-02" )
149
+ after = pd .Timestamp ("2020-08-04" )
150
+
151
+ result = series .truncate (before = before , after = after )
152
+
153
+ # the input Series and the expected Series are the same
154
+ tm .assert_series_equal (result , series )
You can’t perform that action at this time.
0 commit comments