Skip to content

Commit

Permalink
Follow pandas no_default usage more carefully
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed Jan 22, 2023
1 parent beff73a commit 9cd335d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from datetime import datetime, timedelta
from enum import Enum
from functools import partial
from typing import TYPE_CHECKING, ClassVar
from typing import TYPE_CHECKING, ClassVar, Literal

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -866,6 +866,12 @@ 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 All @@ -888,12 +894,12 @@ def _translate_closed_to_inclusive(closed):

def _infer_inclusive(closed, inclusive):
"""Follows code added in pandas #43504."""
if closed is not _NoDefault and inclusive is not None:
if closed is not no_default and inclusive is not None:
raise ValueError(
"Following pandas, deprecated argument `closed` cannot be "
"passed if argument `inclusive` is not None."
)
if closed is not _NoDefault:
if closed is not no_default:
inclusive = _translate_closed_to_inclusive(closed)
elif inclusive is None:
inclusive = "both"
Expand All @@ -907,7 +913,7 @@ def cftime_range(
freq="D",
normalize=False,
name=None,
closed: _NoDefault | SideOptions = _NoDefault,
closed: NoDefault | SideOptions = no_default,
inclusive: None | InclusiveOptions = None,
calendar="standard",
):
Expand Down Expand Up @@ -1143,7 +1149,7 @@ def date_range(
tz=None,
normalize=False,
name=None,
closed: _NoDefault | SideOptions = _NoDefault,
closed: NoDefault | SideOptions = no_default,
inclusive: None | InclusiveOptions = None,
calendar="standard",
use_cftime=None,
Expand Down

0 comments on commit 9cd335d

Please sign in to comment.