Skip to content

Commit 3e65640

Browse files
Enforce Numpy Docstring Validation for pandas.IntervalIndex.contains and pandas.arrays.IntervalArray.contains (#58618)
* DOC: add RT03 for interval contains method * DOC: remove RT03 for interval contains method
1 parent 9df2c78 commit 3e65640

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

ci/code_checks.sh

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7878
-i "pandas.Grouper PR02" \
7979
-i "pandas.Index PR07" \
8080
-i "pandas.Interval PR02" \
81-
-i "pandas.IntervalIndex.contains RT03" \
8281
-i "pandas.IntervalIndex.get_loc PR07,RT03,SA01" \
8382
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
8483
-i "pandas.IntervalIndex.left GL08" \
@@ -413,7 +412,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
413412
-i "pandas.arrays.DatetimeArray SA01" \
414413
-i "pandas.arrays.FloatingArray SA01" \
415414
-i "pandas.arrays.IntegerArray SA01" \
416-
-i "pandas.arrays.IntervalArray.contains RT03" \
417415
-i "pandas.arrays.IntervalArray.is_non_overlapping_monotonic SA01" \
418416
-i "pandas.arrays.IntervalArray.left SA01" \
419417
-i "pandas.arrays.IntervalArray.length SA01" \

pandas/core/arrays/interval.py

+28-10
Original file line numberDiff line numberDiff line change
@@ -1753,22 +1753,40 @@ def repeat(
17531753
"""
17541754
)
17551755

1756-
@Appender(
1757-
_interval_shared_docs["contains"]
1758-
% {
1759-
"klass": "IntervalArray",
1760-
"examples": textwrap.dedent(
1761-
"""\
1756+
def contains(self, other):
1757+
"""
1758+
Check elementwise if the Intervals contain the value.
1759+
1760+
Return a boolean mask whether the value is contained in the Intervals
1761+
of the IntervalArray.
1762+
1763+
Parameters
1764+
----------
1765+
other : scalar
1766+
The value to check whether it is contained in the Intervals.
1767+
1768+
Returns
1769+
-------
1770+
boolean array
1771+
A boolean mask whether the value is contained in the Intervals.
1772+
1773+
See Also
1774+
--------
1775+
Interval.contains : Check whether Interval object contains value.
1776+
IntervalArray.overlaps : Check if an Interval overlaps the values in the
1777+
IntervalArray.
1778+
1779+
Examples
1780+
--------
17621781
>>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)])
17631782
>>> intervals
17641783
<IntervalArray>
17651784
[(0, 1], (1, 3], (2, 4]]
17661785
Length: 3, dtype: interval[int64, right]
1786+
1787+
>>> intervals.contains(0.5)
1788+
array([ True, False, False])
17671789
"""
1768-
),
1769-
}
1770-
)
1771-
def contains(self, other):
17721790
if isinstance(other, Interval):
17731791
raise NotImplementedError("contains not implemented for two intervals")
17741792

0 commit comments

Comments
 (0)