Skip to content

API: Remove IntervalArray from top-level #24926

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
doctests
  • Loading branch information
TomAugspurger committed Jan 25, 2019
commit 86ec7b9951d5097a460e42931bce6ed9ee8f51ae
27 changes: 14 additions & 13 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

_shared_docs_kwargs = dict(
klass='IntervalArray',
qualname='arrays.IntervalArray',
name=''
)

Expand Down Expand Up @@ -248,8 +249,8 @@ def _from_factorized(cls, values, original):

Examples
--------
>>> pd.%(klass)s.from_breaks([0, 1, 2, 3])
%(klass)s([(0, 1], (1, 2], (2, 3]]
>>> pd.%(qualname)s.from_breaks([0, 1, 2, 3])
%(klass)s([(0, 1], (1, 2], (2, 3]],
closed='right',
dtype='interval[int64]')
"""
Expand Down Expand Up @@ -311,7 +312,7 @@ def from_breaks(cls, breaks, closed='right', copy=False, dtype=None):
Examples
--------
>>> %(klass)s.from_arrays([0, 1, 2], [1, 2, 3])
%(klass)s([(0, 1], (1, 2], (2, 3]]
%(klass)s([(0, 1], (1, 2], (2, 3]],
closed='right',
dtype='interval[int64]')
"""
Expand Down Expand Up @@ -354,16 +355,16 @@ def from_arrays(cls, left, right, closed='right', copy=False, dtype=None):

Examples
--------
>>> pd.%(klass)s.from_intervals([pd.Interval(0, 1),
>>> pd.%(qualname)s.from_intervals([pd.Interval(0, 1),
... pd.Interval(1, 2)])
%(klass)s([(0, 1], (1, 2]]
%(klass)s([(0, 1], (1, 2]],
closed='right', dtype='interval[int64]')

The generic Index constructor work identically when it infers an array
of all intervals:

>>> pd.Index([pd.Interval(0, 1), pd.Interval(1, 2)])
%(klass)s([(0, 1], (1, 2]]
%(klass)s([(0, 1], (1, 2]],
closed='right', dtype='interval[int64]')
"""

Expand Down Expand Up @@ -394,7 +395,7 @@ def from_arrays(cls, left, right, closed='right', copy=False, dtype=None):

Examples
--------
>>> pd.%(klass)s.from_tuples([(0, 1), (1, 2)])
>>> pd.%(qualname)s.from_tuples([(0, 1), (1, 2)])
%(klass)s([(0, 1], (1, 2]],
closed='right', dtype='interval[int64]')
"""
Expand Down Expand Up @@ -891,13 +892,13 @@ def closed(self):

Examples
--------
>>> index = pd.interval_range(0, 3)
>>> index
%(klass)s([(0, 1], (1, 2], (2, 3]]
>>> index = pd.interval_range(0, 3)
>>> index
IntervalIndex([(0, 1], (1, 2], (2, 3]],
closed='right',
dtype='interval[int64]')
>>> index.set_closed('both')
%(klass)s([[0, 1], [1, 2], [2, 3]]
>>> index.set_closed('both')
IntervalIndex([[0, 1], [1, 2], [2, 3]],
closed='both',
dtype='interval[int64]')
"""
Expand Down Expand Up @@ -1039,7 +1040,7 @@ def repeat(self, repeats, axis=None):

Examples
--------
>>> intervals = pd.%(klass)s.from_tuples([(0, 1), (1, 3), (2, 4)])
>>> intervals = pd.%(qualname)s.from_tuples([(0, 1), (1, 3), (2, 4)])
>>> intervals
%(klass)s([(0, 1], (1, 3], (2, 4]],
closed='right',
Expand Down
23 changes: 12 additions & 11 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

_index_doc_kwargs.update(
dict(klass='IntervalIndex',
qualname="IntervalIndex",
target_klass='IntervalIndex or list of Intervals',
name=textwrap.dedent("""\
name : object, optional
Expand Down Expand Up @@ -282,10 +283,10 @@ def contains(self, key):
examples="""
Examples
--------
>>> idx = pd.IntervalIndex.from_arrays([0, np.nan, 2], [1, np.nan, 3])
>>> idx.to_tuples()
>>> idx = pd.IntervalIndex.from_arrays([0, np.nan, 2], [1, np.nan, 3])
>>> idx.to_tuples()
Index([(0.0, 1.0), (nan, nan), (2.0, 3.0)], dtype='object')
>>> idx.to_tuples(na_tuple=False)
>>> idx.to_tuples(na_tuple=False)
Index([(0.0, 1.0), nan, (2.0, 3.0)], dtype='object')""",
))
def to_tuples(self, na_tuple=True):
Expand Down Expand Up @@ -1201,47 +1202,47 @@ def interval_range(start=None, end=None, periods=None, freq=None,
Numeric ``start`` and ``end`` is supported.

>>> pd.interval_range(start=0, end=5)
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]]
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
closed='right', dtype='interval[int64]')

Additionally, datetime-like input is also supported.

>>> pd.interval_range(start=pd.Timestamp('2017-01-01'),
end=pd.Timestamp('2017-01-04'))
... end=pd.Timestamp('2017-01-04'))
IntervalIndex([(2017-01-01, 2017-01-02], (2017-01-02, 2017-01-03],
(2017-01-03, 2017-01-04]]
(2017-01-03, 2017-01-04]],
closed='right', dtype='interval[datetime64[ns]]')

The ``freq`` parameter specifies the frequency between the left and right.
endpoints of the individual intervals within the ``IntervalIndex``. For
numeric ``start`` and ``end``, the frequency must also be numeric.

>>> pd.interval_range(start=0, periods=4, freq=1.5)
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]]
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
closed='right', dtype='interval[float64]')

Similarly, for datetime-like ``start`` and ``end``, the frequency must be
convertible to a DateOffset.

>>> pd.interval_range(start=pd.Timestamp('2017-01-01'),
periods=3, freq='MS')
... periods=3, freq='MS')
IntervalIndex([(2017-01-01, 2017-02-01], (2017-02-01, 2017-03-01],
(2017-03-01, 2017-04-01]]
(2017-03-01, 2017-04-01]],
closed='right', dtype='interval[datetime64[ns]]')

Specify ``start``, ``end``, and ``periods``; the frequency is generated
automatically (linearly spaced).

>>> pd.interval_range(start=0, end=6, periods=4)
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]]
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
closed='right',
dtype='interval[float64]')

The ``closed`` parameter specifies which endpoints of the individual
intervals within the ``IntervalIndex`` are closed.

>>> pd.interval_range(end=5, periods=4, closed='both')
IntervalIndex([[1, 2], [2, 3], [3, 4], [4, 5]]
IntervalIndex([[1, 2], [2, 3], [3, 4], [4, 5]],
closed='both', dtype='interval[int64]')
"""
start = com.maybe_box_datetimelike(start)
Expand Down