Skip to content

Commit bd736e4

Browse files
committed
Revert "Revert inclusive default change of IntervalDtype (pandas-dev#47367)"
This reverts commit d9dd128.
1 parent 5700d93 commit bd736e4

File tree

12 files changed

+87
-207
lines changed

12 files changed

+87
-207
lines changed

doc/source/reference/arrays.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ Properties
304304
:toctree: api/
305305

306306
Interval.inclusive
307-
Interval.closed
308307
Interval.closed_left
309308
Interval.closed_right
310309
Interval.is_empty

pandas/_libs/interval.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
6363
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
6464
@property
6565
def inclusive(self) -> IntervalClosedType: ...
66-
@property
67-
def closed(self) -> IntervalClosedType: ...
6866
mid: _MidDescriptor
6967
length: _LengthDescriptor
7068
def __init__(

pandas/_libs/interval.pyx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ from cpython.datetime cimport (
1010
import_datetime,
1111
)
1212

13-
from pandas.util._exceptions import find_stack_level
14-
1513
import_datetime()
1614

1715
cimport cython
@@ -233,7 +231,7 @@ def _warning_interval(inclusive: str | None = None, closed: None | lib.NoDefault
233231
stacklevel=2,
234232
)
235233
if closed is None:
236-
inclusive = "right"
234+
inclusive = "both"
237235
elif closed in ("both", "neither", "left", "right"):
238236
inclusive = closed
239237
else:
@@ -370,7 +368,7 @@ cdef class Interval(IntervalMixin):
370368
inclusive, closed = _warning_interval(inclusive, closed)
371369

372370
if inclusive is None:
373-
inclusive = "right"
371+
inclusive = "both"
374372

375373
if inclusive not in VALID_CLOSED:
376374
raise ValueError(f"invalid option for 'inclusive': {inclusive}")
@@ -385,22 +383,6 @@ cdef class Interval(IntervalMixin):
385383
self.right = right
386384
self.inclusive = inclusive
387385

388-
@property
389-
def closed(self):
390-
"""
391-
String describing the inclusive side the intervals.
392-
393-
.. deprecated:: 1.5.0
394-
395-
Either ``left``, ``right``, ``both`` or ``neither``.
396-
"""
397-
warnings.warn(
398-
"Attribute `closed` is deprecated in favor of `inclusive`.",
399-
FutureWarning,
400-
stacklevel=find_stack_level(inspect.currentframe()),
401-
)
402-
return self.inclusive
403-
404386
def _validate_endpoint(self, endpoint):
405387
# GH 23013
406388
if not (is_integer_object(endpoint) or is_float_object(endpoint) or

pandas/_libs/intervaltree.pxi.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cdef class IntervalTree(IntervalMixin):
6969
inclusive, closed = _warning_interval(inclusive, closed)
7070

7171
if inclusive is None:
72-
inclusive = "right"
72+
inclusive = "both"
7373

7474
if inclusive not in ['left', 'right', 'both', 'neither']:
7575
raise ValueError("invalid option for 'inclusive': %s" % inclusive)

pandas/core/arrays/interval.py

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
cast,
1717
overload,
1818
)
19-
import warnings
2019

2120
import numpy as np
2221

@@ -27,6 +26,7 @@
2726
VALID_CLOSED,
2827
Interval,
2928
IntervalMixin,
29+
_warning_interval,
3030
intervals_to_interval_bounds,
3131
)
3232
from pandas._libs.missing import NA
@@ -44,10 +44,8 @@
4444
from pandas.errors import IntCastingNaNError
4545
from pandas.util._decorators import (
4646
Appender,
47-
deprecate_kwarg,
4847
deprecate_nonkeyword_arguments,
4948
)
50-
from pandas.util._exceptions import find_stack_level
5149

5250
from pandas.core.dtypes.cast import LossySetitemError
5351
from pandas.core.dtypes.common import (
@@ -226,15 +224,16 @@ def ndim(self) -> Literal[1]:
226224
# ---------------------------------------------------------------------
227225
# Constructors
228226

229-
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
230227
def __new__(
231228
cls: type[IntervalArrayT],
232229
data,
233230
inclusive: str | None = None,
231+
closed: None | lib.NoDefault = lib.no_default,
234232
dtype: Dtype | None = None,
235233
copy: bool = False,
236234
verify_integrity: bool = True,
237235
):
236+
inclusive, closed = _warning_interval(inclusive, closed)
238237

239238
data = extract_array(data, extract_numpy=True)
240239

@@ -272,22 +271,24 @@ def __new__(
272271
)
273272

274273
@classmethod
275-
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
276274
def _simple_new(
277275
cls: type[IntervalArrayT],
278276
left,
279277
right,
280278
inclusive=None,
279+
closed: None | lib.NoDefault = lib.no_default,
281280
copy: bool = False,
282281
dtype: Dtype | None = None,
283282
verify_integrity: bool = True,
284283
) -> IntervalArrayT:
285284
result = IntervalMixin.__new__(cls)
286285

286+
inclusive, closed = _warning_interval(inclusive, closed)
287+
287288
if inclusive is None and isinstance(dtype, IntervalDtype):
288289
inclusive = dtype.inclusive
289290

290-
inclusive = inclusive or "right"
291+
inclusive = inclusive or "both"
291292

292293
left = ensure_index(left, copy=copy)
293294
right = ensure_index(right, copy=copy)
@@ -427,17 +428,13 @@ def _from_factorized(
427428
),
428429
}
429430
)
430-
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
431431
def from_breaks(
432432
cls: type[IntervalArrayT],
433433
breaks,
434-
inclusive: IntervalClosedType | None = None,
434+
inclusive="both",
435435
copy: bool = False,
436436
dtype: Dtype | None = None,
437437
) -> IntervalArrayT:
438-
if inclusive is None:
439-
inclusive = "right"
440-
441438
breaks = _maybe_convert_platform_interval(breaks)
442439

443440
return cls.from_arrays(
@@ -508,19 +505,14 @@ def from_breaks(
508505
),
509506
}
510507
)
511-
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
512508
def from_arrays(
513509
cls: type[IntervalArrayT],
514510
left,
515511
right,
516-
inclusive: IntervalClosedType | None = None,
512+
inclusive="both",
517513
copy: bool = False,
518514
dtype: Dtype | None = None,
519515
) -> IntervalArrayT:
520-
521-
if inclusive is None:
522-
inclusive = "right"
523-
524516
left = _maybe_convert_platform_interval(left)
525517
right = _maybe_convert_platform_interval(right)
526518

@@ -582,17 +574,13 @@ def from_arrays(
582574
),
583575
}
584576
)
585-
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
586577
def from_tuples(
587578
cls: type[IntervalArrayT],
588579
data,
589-
inclusive=None,
580+
inclusive="both",
590581
copy: bool = False,
591582
dtype: Dtype | None = None,
592583
) -> IntervalArrayT:
593-
if inclusive is None:
594-
inclusive = "right"
595-
596584
if len(data):
597585
left, right = [], []
598586
else:
@@ -1368,20 +1356,6 @@ def inclusive(self) -> IntervalClosedType:
13681356
"""
13691357
return self.dtype.inclusive
13701358

1371-
@property
1372-
def closed(self) -> IntervalClosedType:
1373-
"""
1374-
String describing the inclusive side the intervals.
1375-
1376-
Either ``left``, ``right``, ``both`` or ``neither`.
1377-
"""
1378-
warnings.warn(
1379-
"Attribute `closed` is deprecated in favor of `inclusive`.",
1380-
FutureWarning,
1381-
stacklevel=find_stack_level(inspect.currentframe()),
1382-
)
1383-
return self.dtype.inclusive
1384-
13851359
_interval_shared_docs["set_closed"] = textwrap.dedent(
13861360
"""
13871361
Return an identical %(klass)s closed on the specified side.
@@ -1421,7 +1395,6 @@ def closed(self) -> IntervalClosedType:
14211395
),
14221396
}
14231397
)
1424-
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
14251398
def set_closed(
14261399
self: IntervalArrayT, inclusive: IntervalClosedType
14271400
) -> IntervalArrayT:

pandas/core/dtypes/dtypes.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
MutableMapping,
1212
cast,
1313
)
14-
import warnings
1514

1615
import numpy as np
1716
import pytz
@@ -43,7 +42,6 @@
4342
npt,
4443
type_t,
4544
)
46-
from pandas.util._exceptions import find_stack_level
4745

4846
from pandas.core.dtypes.base import (
4947
ExtensionDtype,
@@ -1185,15 +1183,6 @@ def _can_hold_na(self) -> bool:
11851183
def inclusive(self):
11861184
return self._closed
11871185

1188-
@property
1189-
def closed(self):
1190-
warnings.warn(
1191-
"Attribute `closed` is deprecated in favor of `inclusive`.",
1192-
FutureWarning,
1193-
stacklevel=find_stack_level(inspect.currentframe()),
1194-
)
1195-
return self._closed
1196-
11971186
@property
11981187
def subtype(self):
11991188
"""

0 commit comments

Comments
 (0)