Skip to content

Commit 8500629

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.IntervalIndex.to_tuples and pandas.arrays.IntervalArray.to_tuples (#58672)
* DOC: add RT03,SA01 to pandas.IntervalIndex.to_tuples * DOC: remove RT03,SA01 to pandas.IntervalIndex.to_tuples
1 parent 81c68dd commit 8500629

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

ci/code_checks.sh

-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7979
-i "pandas.Index PR07" \
8080
-i "pandas.IntervalIndex.left GL08" \
8181
-i "pandas.IntervalIndex.set_closed RT03,SA01" \
82-
-i "pandas.IntervalIndex.to_tuples RT03,SA01" \
8382
-i "pandas.MultiIndex PR01" \
8483
-i "pandas.MultiIndex.append PR07,SA01" \
8584
-i "pandas.MultiIndex.copy PR07,RT03,SA01" \
@@ -405,7 +404,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
405404
-i "pandas.arrays.IntervalArray.mid SA01" \
406405
-i "pandas.arrays.IntervalArray.right SA01" \
407406
-i "pandas.arrays.IntervalArray.set_closed RT03,SA01" \
408-
-i "pandas.arrays.IntervalArray.to_tuples RT03,SA01" \
409407
-i "pandas.arrays.NumpyExtensionArray SA01" \
410408
-i "pandas.arrays.SparseArray PR07,SA01" \
411409
-i "pandas.arrays.TimedeltaArray PR07,SA01" \

pandas/core/arrays/interval.py

+44-32
Original file line numberDiff line numberDiff line change
@@ -1668,39 +1668,51 @@ def __arrow_array__(self, type=None):
16681668
"""
16691669
)
16701670

1671-
@Appender(
1672-
_interval_shared_docs["to_tuples"]
1673-
% {
1674-
"return_type": (
1675-
"ndarray (if self is IntervalArray) or Index (if self is IntervalIndex)"
1676-
),
1677-
"examples": textwrap.dedent(
1678-
"""\
1679-
1680-
Examples
1681-
--------
1682-
For :class:`pandas.IntervalArray`:
1683-
1684-
>>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
1685-
>>> idx
1686-
<IntervalArray>
1687-
[(0, 1], (1, 2]]
1688-
Length: 2, dtype: interval[int64, right]
1689-
>>> idx.to_tuples()
1690-
array([(0, 1), (1, 2)], dtype=object)
1691-
1692-
For :class:`pandas.IntervalIndex`:
1693-
1694-
>>> idx = pd.interval_range(start=0, end=2)
1695-
>>> idx
1696-
IntervalIndex([(0, 1], (1, 2]], dtype='interval[int64, right]')
1697-
>>> idx.to_tuples()
1698-
Index([(0, 1), (1, 2)], dtype='object')
1699-
"""
1700-
),
1701-
}
1702-
)
17031671
def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
1672+
"""
1673+
Return an ndarray (if self is IntervalArray) or Index \
1674+
(if self is IntervalIndex) of tuples of the form (left, right).
1675+
1676+
Parameters
1677+
----------
1678+
na_tuple : bool, default True
1679+
If ``True``, return ``NA`` as a tuple ``(nan, nan)``. If ``False``,
1680+
just return ``NA`` as ``nan``.
1681+
1682+
Returns
1683+
-------
1684+
ndarray or Index
1685+
An ndarray of tuples representing the intervals
1686+
if `self` is an IntervalArray.
1687+
An Index of tuples representing the intervals
1688+
if `self` is an IntervalIndex.
1689+
1690+
See Also
1691+
--------
1692+
IntervalArray.to_list : Convert IntervalArray to a list of tuples.
1693+
IntervalArray.to_numpy : Convert IntervalArray to a numpy array.
1694+
IntervalArray.unique : Find unique intervals in an IntervalArray.
1695+
1696+
Examples
1697+
--------
1698+
For :class:`pandas.IntervalArray`:
1699+
1700+
>>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
1701+
>>> idx
1702+
<IntervalArray>
1703+
[(0, 1], (1, 2]]
1704+
Length: 2, dtype: interval[int64, right]
1705+
>>> idx.to_tuples()
1706+
array([(0, 1), (1, 2)], dtype=object)
1707+
1708+
For :class:`pandas.IntervalIndex`:
1709+
1710+
>>> idx = pd.interval_range(start=0, end=2)
1711+
>>> idx
1712+
IntervalIndex([(0, 1], (1, 2]], dtype='interval[int64, right]')
1713+
>>> idx.to_tuples()
1714+
Index([(0, 1), (1, 2)], dtype='object')
1715+
"""
17041716
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
17051717
if not na_tuple:
17061718
# GH 18756

0 commit comments

Comments
 (0)