Skip to content

DOC: Enforce Numpy Docstring Validation for pandas.IntervalIndex.mid #58657

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 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
-i "pandas.IntervalIndex.left GL08" \
-i "pandas.IntervalIndex.length GL08" \
-i "pandas.IntervalIndex.mid GL08" \
-i "pandas.IntervalIndex.set_closed RT03,SA01" \
-i "pandas.IntervalIndex.to_tuples RT03,SA01" \
-i "pandas.MultiIndex PR01" \
Expand Down
37 changes: 37 additions & 0 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,43 @@ def right(self) -> Index:

@cache_readonly
def mid(self) -> Index:
"""
Return the midpoint of each interval in the IntervalIndex as an Index.

Each midpoint is calculated as the average of the left and right bounds
of each interval. The midpoints are returned as a pandas Index object.

Returns
-------
pandas.Index
An Index containing the midpoints of each interval.

See Also
--------
IntervalIndex.left : Return the left bounds of the intervals
in the IntervalIndex.
IntervalIndex.right : Return the right bounds of the intervals
in the IntervalIndex.
IntervalIndex.length : Return the length of the intervals in
the IntervalIndex.

Notes
-----
The midpoint is the average of the interval bounds, potentially resulting
in a floating-point number even if bounds are integers. The returned Index
will have a dtype that accurately holds the midpoints. This computation is
the same regardless of whether intervals are open or closed.

Examples
--------
>>> iv_idx = pd.IntervalIndex.from_arrays([1, 2, 3], [4, 5, 6])
>>> iv_idx.mid
Float64Index([2.5, 3.5, 4.5], dtype='float64')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a regular Index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I wonder how the test passed. I see similar issue with the right method as well. Fixing both of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the PR description.


>>> iv_idx = pd.IntervalIndex.from_tuples([(1, 4), (2, 5), (3, 6)])
>>> iv_idx.mid
Float64Index([2.5, 3.5, 4.5], dtype='float64')
"""
return Index(self._data.mid, copy=False)

@property
Expand Down
Loading