Skip to content

Commit 9486747

Browse files
committed
Move _NoDefault to pdcompat; fix doc build
1 parent 10c3e9b commit 9486747

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

xarray/coding/cftime_offsets.py

+8-30
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343

4444
import re
4545
from datetime import datetime, timedelta
46-
from enum import Enum
4746
from functools import partial
48-
from typing import TYPE_CHECKING, ClassVar, Literal
47+
from typing import TYPE_CHECKING, ClassVar
4948

5049
import numpy as np
5150
import pandas as pd
@@ -58,7 +57,7 @@
5857
format_cftime_datetime,
5958
)
6059
from xarray.core.common import _contains_datetime_like_objects, is_np_datetime_like
61-
from xarray.core.pdcompat import count_not_none
60+
from xarray.core.pdcompat import NoDefault, count_not_none, no_default
6261
from xarray.core.utils import emit_user_level_warning
6362

6463
try:
@@ -855,29 +854,6 @@ def _generate_range(start, end, periods, offset):
855854
current = next_date
856855

857856

858-
class _NoDefault(Enum):
859-
"""Used by pandas to specify a default value for a deprecated argument.
860-
Copied from pandas._libs.lib._NoDefault.
861-
862-
See also:
863-
- pandas-dev/pandas#30788
864-
- pandas-dev/pandas#40684
865-
- pandas-dev/pandas#40715
866-
- pandas-dev/pandas#47045
867-
"""
868-
869-
no_default = "NO_DEFAULT"
870-
871-
def __repr__(self) -> str:
872-
return "<no_default>"
873-
874-
875-
no_default = (
876-
_NoDefault.no_default
877-
) # Sentinel indicating the default value following pandas
878-
NoDefault = Literal[_NoDefault.no_default] # For typing following pandas
879-
880-
881857
def _translate_closed_to_inclusive(closed):
882858
"""Follows code added in pandas #43504."""
883859
emit_user_level_warning(
@@ -939,12 +915,11 @@ def cftime_range(
939915
Normalize start/end dates to midnight before generating date range.
940916
name : str, default: None
941917
Name of the resulting index
942-
closed : {"left", "right"} or None, default: "NO_DEFAULT"
918+
closed : {None, "left", "right"}, default: "NO_DEFAULT"
943919
Make the interval closed with respect to the given frequency to the
944920
"left", "right", or both sides (None).
945921
946922
.. deprecated:: 2023.01.1
947-
948923
Following pandas, the ``closed`` parameter is deprecated in favor
949924
of the ``inclusive`` parameter, and will be removed in a future
950925
version of xarray.
@@ -968,6 +943,7 @@ def cftime_range(
968943
features of ``pandas.date_range`` (e.g. specifying how the index is
969944
``closed`` on either side, or whether or not to ``normalize`` the start and
970945
end bounds); however, there are some notable exceptions:
946+
971947
- You cannot specify a ``tz`` (time zone) argument.
972948
- Start or end dates specified as partial-datetime strings must use the
973949
`ISO-8601 format <https://en.wikipedia.org/wiki/ISO_8601>`_.
@@ -1186,18 +1162,20 @@ def date_range(
11861162
Normalize start/end dates to midnight before generating date range.
11871163
name : str, default: None
11881164
Name of the resulting index
1189-
closed : {"left", "right"} or None, default: "NO_DEFAULT"
1165+
closed : {None, "left", "right"}, default: "NO_DEFAULT"
11901166
Make the interval closed with respect to the given frequency to the
11911167
"left", "right", or both sides (None).
11921168
11931169
.. deprecated:: 2023.01.1
11941170
Following pandas, the `closed` parameter is deprecated in favor
11951171
of the `inclusive` parameter, and will be removed in a future
11961172
version of xarray.
1197-
inclusive : {None, "both", "neither", "left", "right"}, default None
1173+
1174+
inclusive : {None, "both", "neither", "left", "right"}, default: None
11981175
Include boundaries; whether to set each bound as closed or open.
11991176
12001177
.. versionadded:: 2023.01.1
1178+
12011179
calendar : str, default: "standard"
12021180
Calendar type for the datetimes.
12031181
use_cftime : boolean, optional

xarray/core/pdcompat.py

+26
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,36 @@
3535
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
from __future__ import annotations
3737

38+
from enum import Enum
39+
from typing import Literal
40+
3841

3942
def count_not_none(*args) -> int:
4043
"""Compute the number of non-None arguments.
4144
4245
Copied from pandas.core.common.count_not_none (not part of the public API)
4346
"""
4447
return sum(arg is not None for arg in args)
48+
49+
50+
class _NoDefault(Enum):
51+
"""Used by pandas to specify a default value for a deprecated argument.
52+
Copied from pandas._libs.lib._NoDefault.
53+
54+
See also:
55+
- pandas-dev/pandas#30788
56+
- pandas-dev/pandas#40684
57+
- pandas-dev/pandas#40715
58+
- pandas-dev/pandas#47045
59+
"""
60+
61+
no_default = "NO_DEFAULT"
62+
63+
def __repr__(self) -> str:
64+
return "<no_default>"
65+
66+
67+
no_default = (
68+
_NoDefault.no_default
69+
) # Sentinel indicating the default value following pandas
70+
NoDefault = Literal[_NoDefault.no_default] # For typing following pandas

0 commit comments

Comments
 (0)