-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Updating pandas.Interval docstring #20057
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
Changes from 5 commits
eb8ce9f
e8cbf0b
080654d
f302acc
713d975
a0db247
7db6817
5a6727a
c1d7265
45f7f3b
4682386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,26 +81,70 @@ cdef class Interval(IntervalMixin): | |
|
||
Parameters | ||
---------- | ||
left : value | ||
Left bound for the interval | ||
right : value | ||
Right bound for the interval | ||
left : orderable scalar | ||
Left bound for the interval. | ||
right : orderable scalar | ||
Right bound for the interval. | ||
closed : {'left', 'right', 'both', 'neither'}, default 'right' | ||
Whether the interval is closed on the left-side, right-side, both or | ||
neither | ||
neither. | ||
|
||
Notes | ||
----- | ||
You must be able to compare the parameters `left` and `right`, | ||
and they must satisfy ``left <= right``. | ||
|
||
Examples | ||
-------- | ||
It is possible to build Intervals of different types, like numeric ones | ||
|
||
>>> iv = pd.Interval(left=0, right=5) | ||
>>> iv | ||
Interval(0, 5, closed='right') | ||
|
||
In which you can check if an element belongs to it | ||
|
||
>>> 2.5 in iv | ||
True | ||
|
||
>>> year_2017 = pd.Interval(pd.Timestamp('2017-01-01'), | ||
... pd.Timestamp('2017-12-31'), closed='both') | ||
You can test the bounds | ||
|
||
>>> 0 in iv | ||
False | ||
>>> 5 in iv | ||
True | ||
|
||
Calculate its length | ||
|
||
>>> iv.length | ||
5 | ||
|
||
You can operate with `+` and `*` over an Interval and the operation | ||
is applied to each of its bounds, so the result depends on the type | ||
of the bound elements | ||
|
||
>>> shifted_iv = iv + 3 | ||
>>> shifted_iv | ||
Interval(3, 8, closed='right') | ||
>>> extended_iv = iv * 10.0 | ||
>>> extended_iv | ||
Interval(0.0, 50.0, closed='right') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: Could maybe add that an interval does not necessarily need to be bounded, e.g. |
||
To create a time interval you can use Timestamps as the bounds | ||
|
||
>>> year_2017 = pd.Interval(pd.Timestamp('2017-01-01 00:00:00'), | ||
... pd.Timestamp('2018-01-01 00:00:00'), | ||
... closed='left') | ||
>>> pd.Timestamp('2017-01-01 00:00') in year_2017 | ||
True | ||
>>> year_2017.length | ||
Timedelta('365 days 00:00:00') | ||
|
||
And also you can create string intervals | ||
|
||
>>> volume_1 = pd.Interval('Ant', 'Dog', closed='both') | ||
>>> 'Bee' in volume_1 | ||
True | ||
|
||
See Also | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add Period here as well (its pretty much a time based interval) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add a couple of points here: |
||
-------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add that left & right must be of the same type. (add to Notes)