Skip to content

Commit

Permalink
[test-upstream] Move _NoDefault to pdcompat; fix doc build
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed Feb 4, 2023
1 parent 15f4034 commit 1f0dc88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
38 changes: 8 additions & 30 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@

import re
from datetime import datetime, timedelta
from enum import Enum
from functools import partial
from typing import TYPE_CHECKING, ClassVar, Literal
from typing import TYPE_CHECKING, ClassVar

import numpy as np
import pandas as pd
Expand All @@ -58,7 +57,7 @@
format_cftime_datetime,
)
from xarray.core.common import _contains_datetime_like_objects, is_np_datetime_like
from xarray.core.pdcompat import count_not_none
from xarray.core.pdcompat import NoDefault, count_not_none, no_default
from xarray.core.utils import emit_user_level_warning

try:
Expand Down Expand Up @@ -855,29 +854,6 @@ def _generate_range(start, end, periods, offset):
current = next_date


class _NoDefault(Enum):
"""Used by pandas to specify a default value for a deprecated argument.
Copied from pandas._libs.lib._NoDefault.
See also:
- pandas-dev/pandas#30788
- pandas-dev/pandas#40684
- pandas-dev/pandas#40715
- pandas-dev/pandas#47045
"""

no_default = "NO_DEFAULT"

def __repr__(self) -> str:
return "<no_default>"


no_default = (
_NoDefault.no_default
) # Sentinel indicating the default value following pandas
NoDefault = Literal[_NoDefault.no_default] # For typing following pandas


def _translate_closed_to_inclusive(closed):
"""Follows code added in pandas #43504."""
emit_user_level_warning(
Expand Down Expand Up @@ -939,12 +915,11 @@ def cftime_range(
Normalize start/end dates to midnight before generating date range.
name : str, default: None
Name of the resulting index
closed : {"left", "right"} or None, default: "NO_DEFAULT"
closed : {None, "left", "right"}, default: "NO_DEFAULT"
Make the interval closed with respect to the given frequency to the
"left", "right", or both sides (None).
.. deprecated:: 2023.01.1
Following pandas, the ``closed`` parameter is deprecated in favor
of the ``inclusive`` parameter, and will be removed in a future
version of xarray.
Expand All @@ -968,6 +943,7 @@ def cftime_range(
features of ``pandas.date_range`` (e.g. specifying how the index is
``closed`` on either side, or whether or not to ``normalize`` the start and
end bounds); however, there are some notable exceptions:
- You cannot specify a ``tz`` (time zone) argument.
- Start or end dates specified as partial-datetime strings must use the
`ISO-8601 format <https://en.wikipedia.org/wiki/ISO_8601>`_.
Expand Down Expand Up @@ -1186,18 +1162,20 @@ def date_range(
Normalize start/end dates to midnight before generating date range.
name : str, default: None
Name of the resulting index
closed : {"left", "right"} or None, default: "NO_DEFAULT"
closed : {None, "left", "right"}, default: "NO_DEFAULT"
Make the interval closed with respect to the given frequency to the
"left", "right", or both sides (None).
.. deprecated:: 2023.01.1
Following pandas, the `closed` parameter is deprecated in favor
of the `inclusive` parameter, and will be removed in a future
version of xarray.
inclusive : {None, "both", "neither", "left", "right"}, default None
inclusive : {None, "both", "neither", "left", "right"}, default: None
Include boundaries; whether to set each bound as closed or open.
.. versionadded:: 2023.01.1
calendar : str, default: "standard"
Calendar type for the datetimes.
use_cftime : boolean, optional
Expand Down
26 changes: 26 additions & 0 deletions xarray/core/pdcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,36 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import annotations

from enum import Enum
from typing import Literal


def count_not_none(*args) -> int:
"""Compute the number of non-None arguments.
Copied from pandas.core.common.count_not_none (not part of the public API)
"""
return sum(arg is not None for arg in args)


class _NoDefault(Enum):
"""Used by pandas to specify a default value for a deprecated argument.
Copied from pandas._libs.lib._NoDefault.
See also:
- pandas-dev/pandas#30788
- pandas-dev/pandas#40684
- pandas-dev/pandas#40715
- pandas-dev/pandas#47045
"""

no_default = "NO_DEFAULT"

def __repr__(self) -> str:
return "<no_default>"


no_default = (
_NoDefault.no_default
) # Sentinel indicating the default value following pandas
NoDefault = Literal[_NoDefault.no_default] # For typing following pandas

0 comments on commit 1f0dc88

Please sign in to comment.