Skip to content

Commit 9cd335d

Browse files
committed
Follow pandas no_default usage more carefully
1 parent beff73a commit 9cd335d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

xarray/coding/cftime_offsets.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from datetime import datetime, timedelta
4646
from enum import Enum
4747
from functools import partial
48-
from typing import TYPE_CHECKING, ClassVar
48+
from typing import TYPE_CHECKING, ClassVar, Literal
4949

5050
import numpy as np
5151
import pandas as pd
@@ -866,6 +866,12 @@ def __repr__(self) -> str:
866866
return "<no_default>"
867867

868868

869+
no_default = (
870+
_NoDefault.no_default
871+
) # Sentinel indicating the default value following pandas
872+
NoDefault = Literal[_NoDefault.no_default] # For typing following pandas
873+
874+
869875
def _translate_closed_to_inclusive(closed):
870876
"""Follows code added in pandas #43504."""
871877
emit_user_level_warning(
@@ -888,12 +894,12 @@ def _translate_closed_to_inclusive(closed):
888894

889895
def _infer_inclusive(closed, inclusive):
890896
"""Follows code added in pandas #43504."""
891-
if closed is not _NoDefault and inclusive is not None:
897+
if closed is not no_default and inclusive is not None:
892898
raise ValueError(
893899
"Following pandas, deprecated argument `closed` cannot be "
894900
"passed if argument `inclusive` is not None."
895901
)
896-
if closed is not _NoDefault:
902+
if closed is not no_default:
897903
inclusive = _translate_closed_to_inclusive(closed)
898904
elif inclusive is None:
899905
inclusive = "both"
@@ -907,7 +913,7 @@ def cftime_range(
907913
freq="D",
908914
normalize=False,
909915
name=None,
910-
closed: _NoDefault | SideOptions = _NoDefault,
916+
closed: NoDefault | SideOptions = no_default,
911917
inclusive: None | InclusiveOptions = None,
912918
calendar="standard",
913919
):
@@ -1143,7 +1149,7 @@ def date_range(
11431149
tz=None,
11441150
normalize=False,
11451151
name=None,
1146-
closed: _NoDefault | SideOptions = _NoDefault,
1152+
closed: NoDefault | SideOptions = no_default,
11471153
inclusive: None | InclusiveOptions = None,
11481154
calendar="standard",
11491155
use_cftime=None,

0 commit comments

Comments
 (0)