|
16 | 16 | cast, |
17 | 17 | overload, |
18 | 18 | ) |
19 | | -import warnings |
20 | 19 |
|
21 | 20 | import numpy as np |
22 | 21 |
|
|
27 | 26 | VALID_CLOSED, |
28 | 27 | Interval, |
29 | 28 | IntervalMixin, |
| 29 | + _warning_interval, |
30 | 30 | intervals_to_interval_bounds, |
31 | 31 | ) |
32 | 32 | from pandas._libs.missing import NA |
|
44 | 44 | from pandas.errors import IntCastingNaNError |
45 | 45 | from pandas.util._decorators import ( |
46 | 46 | Appender, |
47 | | - deprecate_kwarg, |
48 | 47 | deprecate_nonkeyword_arguments, |
49 | 48 | ) |
50 | | -from pandas.util._exceptions import find_stack_level |
51 | 49 |
|
52 | 50 | from pandas.core.dtypes.cast import LossySetitemError |
53 | 51 | from pandas.core.dtypes.common import ( |
@@ -226,15 +224,16 @@ def ndim(self) -> Literal[1]: |
226 | 224 | # --------------------------------------------------------------------- |
227 | 225 | # Constructors |
228 | 226 |
|
229 | | - @deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive") |
230 | 227 | def __new__( |
231 | 228 | cls: type[IntervalArrayT], |
232 | 229 | data, |
233 | 230 | inclusive: str | None = None, |
| 231 | + closed: None | lib.NoDefault = lib.no_default, |
234 | 232 | dtype: Dtype | None = None, |
235 | 233 | copy: bool = False, |
236 | 234 | verify_integrity: bool = True, |
237 | 235 | ): |
| 236 | + inclusive, closed = _warning_interval(inclusive, closed) |
238 | 237 |
|
239 | 238 | data = extract_array(data, extract_numpy=True) |
240 | 239 |
|
@@ -272,22 +271,24 @@ def __new__( |
272 | 271 | ) |
273 | 272 |
|
274 | 273 | @classmethod |
275 | | - @deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive") |
276 | 274 | def _simple_new( |
277 | 275 | cls: type[IntervalArrayT], |
278 | 276 | left, |
279 | 277 | right, |
280 | 278 | inclusive=None, |
| 279 | + closed: None | lib.NoDefault = lib.no_default, |
281 | 280 | copy: bool = False, |
282 | 281 | dtype: Dtype | None = None, |
283 | 282 | verify_integrity: bool = True, |
284 | 283 | ) -> IntervalArrayT: |
285 | 284 | result = IntervalMixin.__new__(cls) |
286 | 285 |
|
| 286 | + inclusive, closed = _warning_interval(inclusive, closed) |
| 287 | + |
287 | 288 | if inclusive is None and isinstance(dtype, IntervalDtype): |
288 | 289 | inclusive = dtype.inclusive |
289 | 290 |
|
290 | | - inclusive = inclusive or "right" |
| 291 | + inclusive = inclusive or "both" |
291 | 292 |
|
292 | 293 | left = ensure_index(left, copy=copy) |
293 | 294 | right = ensure_index(right, copy=copy) |
@@ -427,17 +428,13 @@ def _from_factorized( |
427 | 428 | ), |
428 | 429 | } |
429 | 430 | ) |
430 | | - @deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive") |
431 | 431 | def from_breaks( |
432 | 432 | cls: type[IntervalArrayT], |
433 | 433 | breaks, |
434 | | - inclusive: IntervalClosedType | None = None, |
| 434 | + inclusive="both", |
435 | 435 | copy: bool = False, |
436 | 436 | dtype: Dtype | None = None, |
437 | 437 | ) -> IntervalArrayT: |
438 | | - if inclusive is None: |
439 | | - inclusive = "right" |
440 | | - |
441 | 438 | breaks = _maybe_convert_platform_interval(breaks) |
442 | 439 |
|
443 | 440 | return cls.from_arrays( |
@@ -508,19 +505,14 @@ def from_breaks( |
508 | 505 | ), |
509 | 506 | } |
510 | 507 | ) |
511 | | - @deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive") |
512 | 508 | def from_arrays( |
513 | 509 | cls: type[IntervalArrayT], |
514 | 510 | left, |
515 | 511 | right, |
516 | | - inclusive: IntervalClosedType | None = None, |
| 512 | + inclusive="both", |
517 | 513 | copy: bool = False, |
518 | 514 | dtype: Dtype | None = None, |
519 | 515 | ) -> IntervalArrayT: |
520 | | - |
521 | | - if inclusive is None: |
522 | | - inclusive = "right" |
523 | | - |
524 | 516 | left = _maybe_convert_platform_interval(left) |
525 | 517 | right = _maybe_convert_platform_interval(right) |
526 | 518 |
|
@@ -582,17 +574,13 @@ def from_arrays( |
582 | 574 | ), |
583 | 575 | } |
584 | 576 | ) |
585 | | - @deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive") |
586 | 577 | def from_tuples( |
587 | 578 | cls: type[IntervalArrayT], |
588 | 579 | data, |
589 | | - inclusive=None, |
| 580 | + inclusive="both", |
590 | 581 | copy: bool = False, |
591 | 582 | dtype: Dtype | None = None, |
592 | 583 | ) -> IntervalArrayT: |
593 | | - if inclusive is None: |
594 | | - inclusive = "right" |
595 | | - |
596 | 584 | if len(data): |
597 | 585 | left, right = [], [] |
598 | 586 | else: |
@@ -1368,20 +1356,6 @@ def inclusive(self) -> IntervalClosedType: |
1368 | 1356 | """ |
1369 | 1357 | return self.dtype.inclusive |
1370 | 1358 |
|
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 | | - |
1385 | 1359 | _interval_shared_docs["set_closed"] = textwrap.dedent( |
1386 | 1360 | """ |
1387 | 1361 | Return an identical %(klass)s closed on the specified side. |
@@ -1421,7 +1395,6 @@ def closed(self) -> IntervalClosedType: |
1421 | 1395 | ), |
1422 | 1396 | } |
1423 | 1397 | ) |
1424 | | - @deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive") |
1425 | 1398 | def set_closed( |
1426 | 1399 | self: IntervalArrayT, inclusive: IntervalClosedType |
1427 | 1400 | ) -> IntervalArrayT: |
|
0 commit comments