Skip to content

Commit ef3d7c0

Browse files
author
tp
committed
Improved doc string for IntervalIndex + related changes
1 parent eaa5081 commit ef3d7c0

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

pandas/_libs/interval.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ cdef class Interval(IntervalMixin):
5858
closed : {'left', 'right', 'both', 'neither'}
5959
Whether the interval is closed on the left-side, right-side, both or
6060
neither. Defaults to 'right'.
61+
62+
See Also
63+
--------
64+
IntervalIndex : an Index of intervals that are all closed on the same side.
6165
"""
6266

6367
cdef readonly object left, right

pandas/core/indexes/interval.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,42 @@ class IntervalIndex(IntervalMixin, Index):
120120
copy : boolean, default False
121121
Copy the meta-data
122122
123+
Examples
124+
---------
125+
A new ``IntervalIndex`` is typically constructed using
126+
:func:`interval_range`:
127+
128+
>>> pd.interval_range(start=0, end=5)
129+
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]]
130+
closed='right', dtype='interval[int64]')
131+
132+
It may also be constructed using one of the constructor
133+
methods :meth:`IntervalIndex.from_arrays``,
134+
:meth:`IntervalIndex.from_breaks``, :meth:`IntervalIndex.from_intervals`
135+
and :meth:`IntervalIndex.from_tuples``.
136+
137+
See further examples in the doc strings of ``interval_range`` and the
138+
mentioned constructor methods.
139+
140+
Notes
141+
------
142+
See the `user guide
143+
<http://pandas.pydata.org/pandas-docs/stable/advanced.html#intervalindex>`_
144+
for more.
145+
123146
See Also
124147
--------
125148
Index
149+
Interval : A bounded slice-like interval
150+
interval_range : Function to create a fixed frequency IntervalIndex
151+
IntervalIndex.from_arrays : Construct an IntervalIndex from a a left and
152+
right array
153+
IntervalIndex.from_breaks : Construct an IntervalIndex from an array of
154+
splits
155+
IntervalIndex.from_intervals : Construct an IntervalIndex from a array of
156+
Interval objects
157+
IntervalIndex.from_tuples : Construct an IntervalIndex from a list/array of
158+
tuples
126159
"""
127160
_typ = 'intervalindex'
128161
_comparables = ['name']
@@ -415,7 +448,9 @@ def from_tuples(cls, data, closed='right', name=None, copy=False):
415448
416449
Examples
417450
--------
418-
451+
>>> pd.IntervalIndex.from_tuples([(0, 1), (1,2)])
452+
IntervalIndex([(0, 1], (1, 2]],
453+
closed='right', dtype='interval[int64]')
419454
"""
420455
left = []
421456
right = []
@@ -1159,6 +1194,10 @@ def interval_range(start=None, end=None, periods=None, freq=None,
11591194
>>> pd.interval_range(end=5, periods=4, closed='both')
11601195
IntervalIndex([[1, 2], [2, 3], [3, 4], [4, 5]]
11611196
closed='both', dtype='interval[int64]')
1197+
1198+
See Also
1199+
--------
1200+
IntervalIndex : an Index of intervals that are all closed on the same side.
11621201
"""
11631202
if com._count_not_none(start, end, periods) != 2:
11641203
raise ValueError('Of the three parameters: start, end, and periods, '

0 commit comments

Comments
 (0)