Skip to content

Revert Interval/IntervalIndex/interval_range.inclusive deprecation #48116

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 16 commits into from
Aug 18, 2022
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
4 changes: 1 addition & 3 deletions asv_bench/benchmarks/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ def setup(self, bins):
self.datetime_series = pd.Series(
np.random.randint(N, size=N), dtype="datetime64[ns]"
)
self.interval_bins = pd.IntervalIndex.from_breaks(
np.linspace(0, N, bins), "right"
)
self.interval_bins = pd.IntervalIndex.from_breaks(np.linspace(0, N, bins))

def time_cut_int(self, bins):
pd.cut(self.int_series, bins)
Expand Down
5 changes: 2 additions & 3 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ generated/pandas.Index.values,../reference/api/pandas.Index.values
generated/pandas.Index.view,../reference/api/pandas.Index.view
generated/pandas.Index.where,../reference/api/pandas.Index.where
generated/pandas.infer_freq,../reference/api/pandas.infer_freq
generated/pandas.Interval.inclusive,../reference/api/pandas.Interval.inclusive
generated/pandas.Interval.closed,../reference/api/pandas.Interval.closed
generated/pandas.Interval.closed_left,../reference/api/pandas.Interval.closed_left
generated/pandas.Interval.closed_right,../reference/api/pandas.Interval.closed_right
generated/pandas.Interval,../reference/api/pandas.Interval
generated/pandas.IntervalIndex.inclusive,../reference/api/pandas.IntervalIndex.inclusive
generated/pandas.IntervalIndex.closed,../reference/api/pandas.IntervalIndex.closed
generated/pandas.IntervalIndex.contains,../reference/api/pandas.IntervalIndex.contains
generated/pandas.IntervalIndex.from_arrays,../reference/api/pandas.IntervalIndex.from_arrays
generated/pandas.IntervalIndex.from_breaks,../reference/api/pandas.IntervalIndex.from_breaks
Expand All @@ -761,7 +761,6 @@ generated/pandas.IntervalIndex.mid,../reference/api/pandas.IntervalIndex.mid
generated/pandas.IntervalIndex.overlaps,../reference/api/pandas.IntervalIndex.overlaps
generated/pandas.IntervalIndex.right,../reference/api/pandas.IntervalIndex.right
generated/pandas.IntervalIndex.set_closed,../reference/api/pandas.IntervalIndex.set_closed
generated/pandas.IntervalIndex.set_inclusive,../reference/api/pandas.IntervalIndex.set_inclusive
generated/pandas.IntervalIndex.to_tuples,../reference/api/pandas.IntervalIndex.to_tuples
generated/pandas.IntervalIndex.values,../reference/api/pandas.IntervalIndex.values
generated/pandas.Interval.left,../reference/api/pandas.Interval.left
Expand Down
4 changes: 1 addition & 3 deletions doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ Properties
.. autosummary::
:toctree: api/

Interval.inclusive
Interval.closed
Interval.closed_left
Interval.closed_right
Expand Down Expand Up @@ -341,7 +340,7 @@ A collection of intervals may be stored in an :class:`arrays.IntervalArray`.

arrays.IntervalArray.left
arrays.IntervalArray.right
arrays.IntervalArray.inclusive
arrays.IntervalArray.closed
arrays.IntervalArray.mid
arrays.IntervalArray.length
arrays.IntervalArray.is_empty
Expand All @@ -352,7 +351,6 @@ A collection of intervals may be stored in an :class:`arrays.IntervalArray`.
arrays.IntervalArray.contains
arrays.IntervalArray.overlaps
arrays.IntervalArray.set_closed
arrays.IntervalArray.set_inclusive
arrays.IntervalArray.to_tuples


Expand Down
3 changes: 1 addition & 2 deletions doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ IntervalIndex components
IntervalIndex.left
IntervalIndex.right
IntervalIndex.mid
IntervalIndex.inclusive
IntervalIndex.closed
IntervalIndex.length
IntervalIndex.values
IntervalIndex.is_empty
Expand All @@ -251,7 +251,6 @@ IntervalIndex components
IntervalIndex.get_loc
IntervalIndex.get_indexer
IntervalIndex.set_closed
IntervalIndex.set_inclusive
IntervalIndex.contains
IntervalIndex.overlaps
IntervalIndex.to_tuples
Expand Down
10 changes: 5 additions & 5 deletions doc/source/user_guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ Trying to select an ``Interval`` that is not exactly contained in the ``Interval

In [7]: df.loc[pd.Interval(0.5, 2.5)]
---------------------------------------------------------------------------
KeyError: Interval(0.5, 2.5, inclusive='right')
KeyError: Interval(0.5, 2.5, closed='right')

Selecting all ``Intervals`` that overlap a given ``Interval`` can be performed using the
:meth:`~IntervalIndex.overlaps` method to create a boolean indexer.
Expand Down Expand Up @@ -1082,14 +1082,14 @@ of :ref:`frequency aliases <timeseries.offset_aliases>` with datetime-like inter

pd.interval_range(start=pd.Timedelta("0 days"), periods=3, freq="9H")

Additionally, the ``inclusive`` parameter can be used to specify which side(s) the intervals
are closed on. Intervals are closed on the both side by default.
Additionally, the ``closed`` parameter can be used to specify which side(s) the intervals
are closed on. Intervals are closed on the right side by default.

.. ipython:: python

pd.interval_range(start=0, end=4, inclusive="both")
pd.interval_range(start=0, end=4, closed="both")

pd.interval_range(start=0, end=4, inclusive="neither")
pd.interval_range(start=0, end=4, closed="neither")

Specifying ``start``, ``end``, and ``periods`` will generate a range of evenly spaced
intervals from ``start`` to ``end`` inclusively, with ``periods`` number of elements
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Selecting via a specific interval:

.. ipython:: python

df.loc[pd.Interval(1.5, 3.0, "right")]
df.loc[pd.Interval(1.5, 3.0)]

Selecting via a scalar value that is contained *in* the intervals.

Expand Down
14 changes: 7 additions & 7 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -584,18 +584,18 @@ this would previously return ``True`` for any ``Interval`` overlapping an ``Inte

.. code-block:: python

In [4]: pd.Interval(1, 2, inclusive='neither') in ii
In [4]: pd.Interval(1, 2, closed='neither') in ii
Out[4]: True

In [5]: pd.Interval(-10, 10, inclusive='both') in ii
In [5]: pd.Interval(-10, 10, closed='both') in ii
Out[5]: True

*New behavior*:

.. ipython:: python

pd.Interval(1, 2, inclusive='neither') in ii
pd.Interval(-10, 10, inclusive='both') in ii
pd.Interval(1, 2, closed='neither') in ii
pd.Interval(-10, 10, closed='both') in ii

The :meth:`~IntervalIndex.get_loc` method now only returns locations for exact matches to ``Interval`` queries, as opposed to the previous behavior of
returning locations for overlapping matches. A ``KeyError`` will be raised if an exact match is not found.
Expand All @@ -619,7 +619,7 @@ returning locations for overlapping matches. A ``KeyError`` will be raised if a

In [7]: ii.get_loc(pd.Interval(2, 6))
---------------------------------------------------------------------------
KeyError: Interval(2, 6, inclusive='right')
KeyError: Interval(2, 6, closed='right')

Likewise, :meth:`~IntervalIndex.get_indexer` and :meth:`~IntervalIndex.get_indexer_non_unique` will also only return locations for exact matches
to ``Interval`` queries, with ``-1`` denoting that an exact match was not found.
Expand Down Expand Up @@ -680,11 +680,11 @@ Similarly, a ``KeyError`` will be raised for non-exact matches instead of return

In [6]: s[pd.Interval(2, 3)]
---------------------------------------------------------------------------
KeyError: Interval(2, 3, inclusive='right')
KeyError: Interval(2, 3, closed='right')

In [7]: s.loc[pd.Interval(2, 3)]
---------------------------------------------------------------------------
KeyError: Interval(2, 3, inclusive='right')
KeyError: Interval(2, 3, closed='right')

The :meth:`~IntervalIndex.overlaps` method can be used to create a boolean indexer that replicates the
previous behavior of returning overlapping matches.
Expand Down
7 changes: 0 additions & 7 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -823,17 +823,10 @@ Other Deprecations
- Deprecated :attr:`Timedelta.freq` and :attr:`Timedelta.is_populated` (:issue:`46430`)
- Deprecated :attr:`Timedelta.delta` (:issue:`46476`)
- Deprecated passing arguments as positional in :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44802`)
- Deprecated the ``closed`` argument in :meth:`interval_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the methods :meth:`DataFrame.mad`, :meth:`Series.mad`, and the corresponding groupby methods (:issue:`11787`)
- Deprecated positional arguments to :meth:`Index.join` except for ``other``, use keyword-only arguments instead of positional arguments (:issue:`46518`)
- Deprecated positional arguments to :meth:`StringMethods.rsplit` and :meth:`StringMethods.split` except for ``pat``, use keyword-only arguments instead of positional arguments (:issue:`47423`)
- Deprecated indexing on a timezone-naive :class:`DatetimeIndex` using a string representing a timezone-aware datetime (:issue:`46903`, :issue:`36148`)
- Deprecated the ``closed`` argument in :class:`Interval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the ``closed`` argument in :class:`IntervalIndex` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the ``closed`` argument in :class:`IntervalDtype` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the ``closed`` argument in :class:`.IntervalArray` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated :meth:`.IntervalArray.set_closed` and :meth:`.IntervalIndex.set_closed` in favor of ``set_inclusive``; In a future version ``set_closed`` will get removed (:issue:`40245`)
- Deprecated the ``closed`` argument in :class:`ArrowInterval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated allowing ``unit="M"`` or ``unit="Y"`` in :class:`Timestamp` constructor with a non-round float value (:issue:`47267`)
- Deprecated the ``display.column_space`` global configuration option (:issue:`7576`)
- Deprecated the argument ``na_sentinel`` in :func:`factorize`, :meth:`Index.factorize`, and :meth:`.ExtensionArray.factorize`; pass ``use_na_sentinel=True`` instead to use the sentinel ``-1`` for NaN values and ``use_na_sentinel=False`` instead of ``na_sentinel=None`` to encode NaN values (:issue:`46910`)
Expand Down
26 changes: 8 additions & 18 deletions pandas/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ from typing import (
import numpy as np
import numpy.typing as npt

from pandas._libs import lib
from pandas._typing import (
IntervalInclusiveType,
IntervalClosedType,
Timedelta,
Timestamp,
)

VALID_INCLUSIVE: frozenset[str]
VALID_CLOSED: frozenset[str]

_OrderableScalarT = TypeVar("_OrderableScalarT", int, float)
_OrderableTimesT = TypeVar("_OrderableTimesT", Timestamp, Timedelta)
Expand Down Expand Up @@ -50,31 +49,22 @@ class IntervalMixin:
def open_right(self) -> bool: ...
@property
def is_empty(self) -> bool: ...
def _check_inclusive_matches(
self, other: IntervalMixin, name: str = ...
) -> None: ...

def _warning_interval(
inclusive, closed
) -> tuple[IntervalInclusiveType, lib.NoDefault]: ...
def _check_closed_matches(self, other: IntervalMixin, name: str = ...) -> None: ...

class Interval(IntervalMixin, Generic[_OrderableT]):
@property
def left(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def inclusive(self) -> IntervalInclusiveType: ...
@property
def closed(self) -> IntervalInclusiveType: ...
def closed(self) -> IntervalClosedType: ...
mid: _MidDescriptor
length: _LengthDescriptor
def __init__(
self,
left: _OrderableT,
right: _OrderableT,
inclusive: IntervalInclusiveType = ...,
closed: IntervalInclusiveType = ...,
closed: IntervalClosedType = ...,
) -> None: ...
def __hash__(self) -> int: ...
@overload
Expand Down Expand Up @@ -157,15 +147,15 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...

def intervals_to_interval_bounds(
intervals: np.ndarray, validate_inclusive: bool = ...
) -> tuple[np.ndarray, np.ndarray, IntervalInclusiveType]: ...
intervals: np.ndarray, validate_closed: bool = ...
) -> tuple[np.ndarray, np.ndarray, str]: ...

class IntervalTree(IntervalMixin):
def __init__(
self,
left: np.ndarray,
right: np.ndarray,
inclusive: IntervalInclusiveType = ...,
closed: IntervalClosedType = ...,
leaf_size: int = ...,
) -> None: ...
@property
Expand Down
Loading