Skip to content

Enforce Numpy Docstring Validation for pandas.IntervalIndex.contains and pandas.arrays.IntervalArray.contains #58618

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

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Grouper PR02" \
-i "pandas.Index PR07" \
-i "pandas.Interval PR02" \
-i "pandas.IntervalIndex.contains RT03" \
-i "pandas.IntervalIndex.get_loc PR07,RT03,SA01" \
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
-i "pandas.IntervalIndex.left GL08" \
Expand Down Expand Up @@ -415,7 +414,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.arrays.DatetimeArray SA01" \
-i "pandas.arrays.FloatingArray SA01" \
-i "pandas.arrays.IntegerArray SA01" \
-i "pandas.arrays.IntervalArray.contains RT03" \
-i "pandas.arrays.IntervalArray.is_non_overlapping_monotonic SA01" \
-i "pandas.arrays.IntervalArray.left SA01" \
-i "pandas.arrays.IntervalArray.length SA01" \
Expand Down
38 changes: 28 additions & 10 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,22 +1753,40 @@ def repeat(
"""
)

@Appender(
_interval_shared_docs["contains"]
% {
"klass": "IntervalArray",
"examples": textwrap.dedent(
"""\
def contains(self, other):
"""
Check elementwise if the Intervals contain the value.

Return a boolean mask whether the value is contained in the Intervals
of the IntervalArray.

Parameters
----------
other : scalar
The value to check whether it is contained in the Intervals.

Returns
-------
boolean array
A boolean mask whether the value is contained in the Intervals.

See Also
--------
Interval.contains : Check whether Interval object contains value.
IntervalArray.overlaps : Check if an Interval overlaps the values in the
IntervalArray.

Examples
--------
>>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)])
>>> intervals
<IntervalArray>
[(0, 1], (1, 3], (2, 4]]
Length: 3, dtype: interval[int64, right]

>>> intervals.contains(0.5)
array([ True, False, False])
"""
),
}
)
def contains(self, other):
if isinstance(other, Interval):
raise NotImplementedError("contains not implemented for two intervals")

Expand Down