Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update truncate() documentation and testcases
  • Loading branch information
gliptak committed May 6, 2016
commit 27379dd609890be5abef332ee5d889b5b35c97c8
7 changes: 4 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4633,14 +4633,15 @@ def tshift(self, periods=1, freq=None, axis=0):

def truncate(self, before=None, after=None, axis=None, copy=True):
"""Truncates a sorted NDFrame before and/or after some particular
dates.
index value. If the axis contains only datetime values, before/after
parameters are converted to datetime values.

Parameters
----------
before : date
Truncate before date
Truncate before index value
after : date
Truncate after date
Truncate after index value
axis : the truncation axis, defaults to the stat axis
copy : boolean, default is True,
return a copy of the truncated section
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ def test_describe_none(self):
expected = Series([0, 0], index=['count', 'unique'], name='None')
assert_series_equal(noneSeries.describe(), expected)

def test_truncate_outofbounds(self):
# GH11382
small = pd.Series(data=range(int(2e3)), index=range(int(2e3)))
assert_series_equal(small.truncate(), small)
assert_series_equal(small.truncate(before=0, after=3e3), small)
assert_series_equal(small.truncate(before=-1, after=2e3), small)
big = pd.Series(data=range(int(2e6)), index=range(int(2e6)))
assert_series_equal(big.truncate(), big)
assert_series_equal(big.truncate(before=0, after=3e6), big)
assert_series_equal(big.truncate(before=-1, after=2e6), big)

def test_to_xarray(self):

tm._skip_if_no_xarray()
Expand Down