@@ -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