32
32
import numpy as np
33
33
import pandas as pd
34
34
35
- try :
36
- if sys .version_info >= (3 , 10 ):
37
- from typing import TypeGuard
38
- else :
39
- from typing_extensions import TypeGuard
40
- TypeGuardHashable = TypeGuard [Hashable ]
41
- except ImportError :
42
- TypeGuardHashable = bool
43
-
44
35
45
36
K = TypeVar ("K" )
46
37
V = TypeVar ("V" )
@@ -301,11 +292,7 @@ def either_dict_or_kwargs(
301
292
return pos_kwargs
302
293
303
294
304
- def is_scalar (value : Any , include_0d : bool = True ) -> TypeGuardHashable :
305
- """Whether to treat a value as a scalar.
306
-
307
- Any non-iterable, string, or 0-D array
308
- """
295
+ def _is_scalar (value , include_0d ):
309
296
from .variable import NON_NUMPY_SUPPORTED_ARRAY_TYPES
310
297
311
298
if include_0d :
@@ -320,6 +307,27 @@ def is_scalar(value: Any, include_0d: bool = True) -> TypeGuardHashable:
320
307
)
321
308
322
309
310
+ try :
311
+ if sys .version_info >= (3 , 10 ):
312
+ from typing import TypeGuard
313
+ else :
314
+ from typing_extensions import TypeGuard
315
+ except ImportError :
316
+ def is_scalar (value : Any , include_0d : bool = True ) -> bool :
317
+ """Whether to treat a value as a scalar.
318
+
319
+ Any non-iterable, string, or 0-D array
320
+ """
321
+ return _is_scalar (value , include_0d )
322
+ else :
323
+ def is_scalar (value : Any , include_0d : bool = True ) -> TypeGuard [Hashable ]:
324
+ """Whether to treat a value as a scalar.
325
+
326
+ Any non-iterable, string, or 0-D array
327
+ """
328
+ return _is_scalar (value , include_0d )
329
+
330
+
323
331
def is_valid_numpy_dtype (dtype : Any ) -> bool :
324
332
try :
325
333
np .dtype (dtype )
0 commit comments