Skip to content

Commit

Permalink
another try
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Jul 22, 2021
1 parent 8607b2e commit 2191fbc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion doc/getting-started-guide/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Required dependencies

- Python (3.7 or later)
- setuptools (40.4 or later)
- typing-extensions (3.10 or later)
- `numpy <http://www.numpy.org/>`__ (1.17 or later)
- `pandas <http://pandas.pydata.org/>`__ (1.0 or later)

Expand Down
36 changes: 22 additions & 14 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@
import numpy as np
import pandas as pd

try:
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard
TypeGuardHashable = TypeGuard[Hashable]
except ImportError:
TypeGuardHashable = bool


K = TypeVar("K")
V = TypeVar("V")
Expand Down Expand Up @@ -301,11 +292,7 @@ def either_dict_or_kwargs(
return pos_kwargs


def is_scalar(value: Any, include_0d: bool = True) -> TypeGuardHashable:
"""Whether to treat a value as a scalar.
Any non-iterable, string, or 0-D array
"""
def _is_scalar(value, include_0d):
from .variable import NON_NUMPY_SUPPORTED_ARRAY_TYPES

if include_0d:
Expand All @@ -320,6 +307,27 @@ def is_scalar(value: Any, include_0d: bool = True) -> TypeGuardHashable:
)


try:
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard
except ImportError:
def is_scalar(value: Any, include_0d: bool = True) -> bool:
"""Whether to treat a value as a scalar.
Any non-iterable, string, or 0-D array
"""
return _is_scalar(value, include_0d)
else:
def is_scalar(value: Any, include_0d: bool = True) -> TypeGuard[Hashable]:
"""Whether to treat a value as a scalar.
Any non-iterable, string, or 0-D array
"""
return _is_scalar(value, include_0d)


def is_valid_numpy_dtype(dtype: Any) -> bool:
try:
np.dtype(dtype)
Expand Down

0 comments on commit 2191fbc

Please sign in to comment.