Skip to content

Commit f928b46

Browse files
jschendeljorisvandenbossche
authored andcommitted
DOC: Modify IntervalArray/IntervalIndex docstrings to pass validate_docstrings.py (#23157)
1 parent ff55b32 commit f928b46

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

ci/code_checks.sh

+7
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
145145
-k"-crosstab -pivot_table -cut"
146146
RET=$(($RET + $?)) ; echo $MSG "DONE"
147147

148+
MSG='Doctests interval classes' ; echo $MSG
149+
pytest --doctest-modules -v \
150+
pandas/core/indexes/interval.py \
151+
pandas/core/arrays/interval.py \
152+
-k"-from_arrays -from_breaks -from_intervals -from_tuples -get_loc -set_closed -to_tuples -interval_range"
153+
RET=$(($RET + $?)) ; echo $MSG "DONE"
154+
148155
fi
149156

150157
exit $RET

pandas/core/arrays/interval.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
)
3434

3535

36-
_interval_shared_docs['class'] = """%(summary)s
36+
_interval_shared_docs['class'] = """
37+
%(summary)s
3738
3839
.. versionadded:: %(versionadded)s
3940
@@ -50,13 +51,15 @@
5051
closed : {'left', 'right', 'both', 'neither'}, default 'right'
5152
Whether the intervals are closed on the left-side, right-side, both or
5253
neither.
53-
%(name)s\
54-
copy : boolean, default False
55-
Copy the meta-data.
5654
dtype : dtype or None, default None
57-
If None, dtype will be inferred
55+
If None, dtype will be inferred.
5856
5957
.. versionadded:: 0.23.0
58+
copy : bool, default False
59+
Copy the input data.
60+
%(name)s\
61+
verify_integrity : bool, default True
62+
Verify that the %(klass)s is valid.
6063
6164
Attributes
6265
----------
@@ -87,18 +90,35 @@
8790
See Also
8891
--------
8992
Index : The base pandas Index type
90-
Interval : A bounded slice-like interval; the elements of an IntervalIndex
93+
Interval : A bounded slice-like interval; the elements of an %(klass)s
9194
interval_range : Function to create a fixed frequency IntervalIndex
92-
cut, qcut : Convert arrays of continuous data into Categoricals/Series of
93-
Intervals
95+
cut : Bin values into discrete Intervals
96+
qcut : Bin values into equal-sized Intervals based on rank or sample quantiles
9497
"""
9598

9699

100+
# TODO(jschendel) use a more direct call in Examples when made public (GH22860)
97101
@Appender(_interval_shared_docs['class'] % dict(
98102
klass="IntervalArray",
99-
summary="Pandas array for interval data that are closed on the same side",
103+
summary="Pandas array for interval data that are closed on the same side.",
100104
versionadded="0.24.0",
101-
name='', extra_methods='', examples='',
105+
name='',
106+
extra_methods='',
107+
examples=textwrap.dedent("""\
108+
Examples
109+
--------
110+
A new ``IntervalArray`` can be constructed directly from an array-like of
111+
``Interval`` objects:
112+
113+
>>> pd.core.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)])
114+
IntervalArray([(0, 1], (1, 5]],
115+
closed='right',
116+
dtype='interval[int64]')
117+
118+
It may also be constructed using one of the constructor
119+
methods: :meth:`IntervalArray.from_arrays`,
120+
:meth:`IntervalArray.from_breaks`, and :meth:`IntervalArray.from_tuples`.
121+
"""),
102122
))
103123
@add_metaclass(_WritableDoc)
104124
class IntervalArray(IntervalMixin, ExtensionArray):

pandas/core/indexes/interval.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
target_klass='IntervalIndex or list of Intervals',
5454
name=textwrap.dedent("""\
5555
name : object, optional
56-
to be stored in the index.
56+
Name to be stored in the index.
5757
"""),
5858
))
5959

@@ -116,15 +116,15 @@ def _new_IntervalIndex(cls, d):
116116
versionadded="0.20.0",
117117
extra_methods="contains\n",
118118
examples=textwrap.dedent("""\
119-
120119
Examples
121120
--------
122121
A new ``IntervalIndex`` is typically constructed using
123122
:func:`interval_range`:
124123
125124
>>> pd.interval_range(start=0, end=5)
126-
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]]
127-
closed='right', dtype='interval[int64]')
125+
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
126+
closed='right',
127+
dtype='interval[int64]')
128128
129129
It may also be constructed using one of the constructor
130130
methods: :meth:`IntervalIndex.from_arrays`,

0 commit comments

Comments
 (0)