home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 884652940

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/pull/5624#issuecomment-884652940 https://api.github.com/repos/pydata/xarray/issues/5624 884652940 IC_kwDOAMm_X840uruM 5635139 2021-07-22T04:45:23Z 2021-07-22T04:45:23Z MEMBER

It's not pretty, but this seems to work, on top of the most recent commit 2191fbc:

```diff diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 232dbec3..3b490dcc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,6 +43,7 @@ repos: types-pytz, # Dependencies that are typed numpy, + typing-extensions==3.10.0.0, ] # run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194 # - repo: https://github.com/asottile/pyupgrade diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 1f2dfb5c..a139d2ef 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -10,6 +10,7 @@ import warnings from enum import Enum from typing import ( + TYPE_CHECKING, Any, Callable, Collection, @@ -32,7 +33,6 @@ import numpy as np import pandas as pd

- K = TypeVar("K") V = TypeVar("V") T = TypeVar("T") @@ -307,19 +307,29 @@ def _is_scalar(value, include_0d): )

+# See GH5624, this is a convoluted way to allow type-checking to use TypeGuard without +# requiring typing_extensions as a required dependency to run the code (it is required +# to type-check). 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. + if TYPE_CHECKING: + raise + else: + + 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) +

  • 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.

```

It works with or without the edit to .pre-commit-config.yaml

@shoyer want me to add it on and merge?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  948890466
Powered by Datasette · Queries took 1.58ms · About: xarray-datasette