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 @@ -9397,7 +9397,7 @@ def truncate(
9397
9397
if before > after :
9398
9398
raise ValueError (f"Truncate: { after } must be after { before } " )
9399
9399
9400
- if ax .is_monotonic_decreasing :
9400
+ if len ( ax ) > 1 and ax .is_monotonic_decreasing :
9401
9401
before , after = after , before
9402
9402
9403
9403
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