Skip to content

Commit 0e07474

Browse files
committed
Fix the example in contain method
1 parent 474b4c4 commit 0e07474

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

pandas/core/arrays/interval.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,9 @@ def repeat(self, repeats, axis=None):
11011101
right_repeat = self.right.repeat(repeats)
11021102
return self._shallow_copy(left=left_repeat, right=right_repeat)
11031103

1104-
11051104
_interval_shared_docs[
11061105
"contains"
1107-
] = """
1106+
] = textwrap.dedent("""
11081107
Check elementwise if the Intervals contain the value.
11091108
11101109
Return a boolean mask whether the value is contained in the Intervals
@@ -1129,16 +1128,21 @@ def repeat(self, repeats, axis=None):
11291128
11301129
Examples
11311130
--------
1132-
>>> intervals = pd.%(qualname)s.from_tuples([(0, 1), (1, 3), (2, 4)])
1131+
%(examples)s
1132+
""")
1133+
1134+
@Appender(_interval_shared_docs["contains"] % dict(
1135+
klass="IntervalArray",
1136+
examples=textwrap.dedent("""
1137+
>>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)])
11331138
>>> intervals
1134-
%(klass)s([(0, 1], (1, 3], (2, 4]],
1135-
closed='right',
1136-
dtype='interval[int64]')
1139+
<IntervalArray>
1140+
[(0, 1], (1, 3], (2, 4]]
1141+
Length: 3, closed: right, dtype: interval[int64]
11371142
>>> intervals.contains(0.5)
11381143
array([ True, False, False])
1139-
"""
1140-
1141-
@Appender(_interval_shared_docs["contains"] % _shared_docs_kwargs)
1144+
"""),
1145+
))
11421146
def contains(self, other):
11431147
if isinstance(other, Interval):
11441148
raise NotImplementedError("contains not implemented for two intervals")

pandas/core/indexes/interval.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,12 +1230,23 @@ def equals(self, other):
12301230
and self.closed == other.closed
12311231
)
12321232

1233-
@Appender(_interval_shared_docs["contains"] % _index_doc_kwargs)
1233+
@Appender(_interval_shared_docs["contains"] % dict(
1234+
klass="IntervalIndex",
1235+
examples=textwrap.dedent("""\
1236+
>>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)])
1237+
>>> intervals
1238+
IntervalIndex([(0, 1], (1, 3], (2, 4]],
1239+
closed='right',
1240+
dtype='interval[int64]')
1241+
>>> intervals.contains(0.5)
1242+
array([ True, False, False])
1243+
"""),
1244+
))
12341245
def contains(self, other):
12351246
return self._data.contains(other)
12361247

12371248
@Appender(_interval_shared_docs["overlaps"] % dict(
1238-
klass='IntervalIndex',
1249+
klass="IntervalIndex",
12391250
examples=textwrap.dedent("""\
12401251
>>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)])
12411252
>>> intervals

0 commit comments

Comments
 (0)