Skip to content
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

ENH: consistency of input args for boundaries - Interval #46522

Merged
merged 89 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
538ba43
Update interval.pyi
Mar 26, 2022
a9da7bd
Update interval.pyx
Mar 26, 2022
b222280
Update intervaltree.pxi.in
Mar 26, 2022
466f35a
Update lib.pyx
Mar 26, 2022
323f0d8
Update asserters.py
Mar 26, 2022
c4931c9
Update _arrow_utils.py
Mar 26, 2022
40bfa76
Update interval.py
Mar 26, 2022
23ad9c8
Update cast.py
Mar 26, 2022
f700477
Update dtypes.py
Mar 26, 2022
3835d29
Update interval.py
Mar 26, 2022
6ac2f6a
Update blocks.py
Mar 26, 2022
e53605d
Update tile.py
Mar 26, 2022
8a8f38c
first
Mar 26, 2022
97f7b9e
add
Mar 27, 2022
d20b1be
Merge branch 'main' into enh-consistency-interval-index
Mar 27, 2022
a8a3266
pre commit
Mar 27, 2022
a4d58dc
pre commit
Mar 27, 2022
edf53b7
pre commit
Mar 27, 2022
d0f17c0
pre commit
Mar 27, 2022
b00a947
pre commit
Mar 27, 2022
8f3991d
interval
Mar 27, 2022
5bc735b
doc
Mar 27, 2022
eb3d9ec
doc
Mar 27, 2022
0a41668
doc
Mar 27, 2022
c1f9de4
pre commit
Mar 27, 2022
7d9db8b
pre commit
Mar 27, 2022
49b35cf
pre commit
Mar 27, 2022
4394ad4
Merge branch 'main' of https://github.com/weikhor/pandas into enh-con…
Mar 28, 2022
5703c01
test
Mar 28, 2022
8f6fa54
Merge branch 'main' into enh-consistency-interval-index
Mar 28, 2022
816da28
test
Mar 29, 2022
b1dead8
Merge branch 'main' into enh-consistency-interval-index
Mar 29, 2022
3efc78f
test
Mar 30, 2022
2a9d176
Merge branch 'main' into enh-consistency-interval-index
Mar 30, 2022
59005ec
test
Mar 30, 2022
be88126
Update v0.20.0.rst
Mar 30, 2022
5588b1a
Update interval.py
Mar 30, 2022
217348b
Update interval.py
Mar 30, 2022
7260fcb
Update tile.py
Mar 30, 2022
ddeac18
Merge branch 'main' into enh-consistency-interval-index
Mar 30, 2022
707fd4a
test
Mar 31, 2022
340b66d
Merge branch 'main' into enh-consistency-interval-index
Mar 31, 2022
12e93d5
add
Mar 31, 2022
90eea5c
test
Mar 31, 2022
865e9e4
doc
Mar 31, 2022
59f4681
doc
Apr 2, 2022
e0668d3
doc
Apr 2, 2022
9acc1ba
Merge branch 'main' into enh-consistency-interval-index
Apr 2, 2022
f18fe3a
test
Apr 2, 2022
72d5a0c
test
Apr 3, 2022
3e8fc9a
:Merge branch 'main' of https://github.com/weikhor/pandas into enh-co…
Apr 3, 2022
9461b42
test
Apr 3, 2022
14e9311
test
Apr 3, 2022
eb39213
test
Apr 3, 2022
eb2e95a
test
Apr 3, 2022
4713022
test
Apr 3, 2022
fafd961
test
Apr 3, 2022
611a27f
test
Apr 3, 2022
e339d4d
Merge branch 'main' into enh-consistency-interval-index
Apr 4, 2022
bd2a573
Merge branch 'main' into enh-consistency-interval-index
Apr 5, 2022
1bb0474
Merge branch 'main' of https://github.com/weikhor/pandas into enh-con…
Apr 9, 2022
56d7b25
pre commit
Apr 9, 2022
90ceec4
Merge branch 'main' into enh-consistency-interval-index
Apr 14, 2022
27ea3a8
Merge branch 'main' into enh-consistency-interval-index
Apr 17, 2022
74f3a0f
Merge branch 'main' into enh-consistency-interval-index
Apr 18, 2022
45b318f
Merge branch 'main' into enh-consistency-interval-index
Apr 28, 2022
86a67b0
Merge branch 'main' into enh-consistency-interval-index
Apr 28, 2022
d4c2212
add
Apr 29, 2022
c0653ee
add helper function
May 16, 2022
4f6b499
Merge branch 'main' into enh-consistency-interval-index
May 16, 2022
67922fc
Merge branch 'main' into enh-consistency-interval-index
May 16, 2022
c32384e
interval
May 16, 2022
6b8cd69
Merge branch 'main' into enh-consistency-interval-index
May 18, 2022
eab8b58
update warning_interval
May 18, 2022
f234f07
resolve conflict
May 19, 2022
ff53d3f
Merge branch 'main' into enh-consistency-interval-index
May 19, 2022
fe62e50
pickle
May 19, 2022
a73ec91
Update dtypes.py
May 19, 2022
12c7806
Merge branch 'main' into enh-consistency-interval-index
May 20, 2022
757cabf
pickle
May 24, 2022
82d58b0
pickle
May 24, 2022
4e3d167
mrege conflict
May 26, 2022
03890df
resolve warning
May 26, 2022
c8c6193
Merge branch 'main' into enh-consistency-interval-index
May 27, 2022
41f59fb
mypy
May 28, 2022
17b54ad
Merge branch 'main' into enh-consistency-interval-index
May 28, 2022
b73f4ba
Merge branch 'main' into enh-consistency-interval-index
May 28, 2022
8cbeca0
Merge branch 'main' into enh-consistency-interval-index
May 29, 2022
35b18ea
Merge branch 'main' into enh-consistency-interval-index
May 30, 2022
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: 3 additions & 1 deletion asv_bench/benchmarks/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ 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))
self.interval_bins = pd.IntervalIndex.from_breaks(
np.linspace(0, N, bins), "right"
)

def time_cut_int(self, bins):
pd.cut(self.int_series, bins)
Expand Down
4 changes: 2 additions & 2 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.closed,../reference/api/pandas.Interval.closed
generated/pandas.Interval.inclusive,../reference/api/pandas.Interval.inclusive
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.closed,../reference/api/pandas.IntervalIndex.closed
generated/pandas.IntervalIndex.inclusive,../reference/api/pandas.IntervalIndex.inclusive
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 Down
4 changes: 2 additions & 2 deletions doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Properties
.. autosummary::
:toctree: api/

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

arrays.IntervalArray.left
arrays.IntervalArray.right
arrays.IntervalArray.closed
arrays.IntervalArray.inclusive
arrays.IntervalArray.mid
arrays.IntervalArray.length
arrays.IntervalArray.is_empty
Expand Down
2 changes: 1 addition & 1 deletion 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.closed
IntervalIndex.inclusive
IntervalIndex.length
IntervalIndex.values
IntervalIndex.is_empty
Expand Down
2 changes: 1 addition & 1 deletion 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, closed='right')
KeyError: Interval(0.5, 2.5, inclusive='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
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)]
df.loc[pd.Interval(1.5, 3.0, "right")]

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, closed='neither') in ii
In [4]: pd.Interval(1, 2, inclusive='neither') in ii
Out[4]: True

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

*New behavior*:

.. ipython:: python

pd.Interval(1, 2, closed='neither') in ii
pd.Interval(-10, 10, closed='both') in ii
pd.Interval(1, 2, inclusive='neither') in ii
pd.Interval(-10, 10, inclusive='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, closed='right')
KeyError: Interval(2, 6, inclusive='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, closed='right')
KeyError: Interval(2, 3, inclusive='right')

In [7]: s.loc[pd.Interval(2, 3)]
---------------------------------------------------------------------------
KeyError: Interval(2, 3, closed='right')
KeyError: Interval(2, 3, inclusive='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: 6 additions & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,12 @@ Other Deprecations
- 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 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 the ``closed`` argument in :class:`intervaltree` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
- Deprecated the ``closed`` argument in :class:`ArrowInterval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.performance:
Expand Down
10 changes: 8 additions & 2 deletions pandas/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from typing import (
import numpy as np
import numpy.typing as npt

from pandas._libs import lib
from pandas._typing import (
IntervalClosedType,
Timedelta,
Expand Down Expand Up @@ -54,19 +55,24 @@ class IntervalMixin:
def is_empty(self) -> bool: ...
def _check_closed_matches(self, other: IntervalMixin, name: str = ...) -> None: ...

def _warning_interval(
inclusive, closed
) -> tuple[IntervalClosedType, lib.NoDefault]: ...

class Interval(IntervalMixin, Generic[_OrderableT]):
@property
def left(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def closed(self) -> IntervalClosedType: ...
def inclusive(self) -> IntervalClosedType: ...
mid: _MidDescriptor
length: _LengthDescriptor
def __init__(
self,
left: _OrderableT,
right: _OrderableT,
inclusive: IntervalClosedType = ...,
closed: IntervalClosedType = ...,
) -> None: ...
def __hash__(self) -> int: ...
Expand Down Expand Up @@ -157,7 +163,7 @@ class IntervalTree(IntervalMixin):
self,
left: np.ndarray,
right: np.ndarray,
closed: IntervalClosedType = ...,
inclusive: IntervalClosedType = ...,
leaf_size: int = ...,
) -> None: ...
@property
Expand Down
Loading