Skip to content

Commit 5dc03cb

Browse files
committed
Address remaining functions
1 parent 3ca3945 commit 5dc03cb

File tree

9 files changed

+72
-13
lines changed

9 files changed

+72
-13
lines changed

pandas/_libs/lib.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ from cython cimport (
4141
from pandas._config import using_string_dtype
4242

4343
from pandas._libs.missing import check_na_tuples_nonequal
44+
from pandas.util._decorators import set_module
4445

4546
import_datetime()
4647

@@ -154,6 +155,7 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t:
154155
# ----------------------------------------------------------------------
155156

156157

158+
@set_module("pandas.api.types")
157159
def is_scalar(val: object) -> bool:
158160
"""
159161
Return True if given object is scalar.
@@ -255,6 +257,7 @@ cdef int64_t get_itemsize(object val):
255257
return -1
256258

257259

260+
@set_module("pandas.api.types")
258261
def is_iterator(obj: object) -> bool:
259262
"""
260263
Check if the object is an iterator.
@@ -1095,6 +1098,7 @@ def indices_fast(ndarray[intp_t, ndim=1] index, const int64_t[:] labels, list ke
10951098

10961099
# core.common import for fast inference checks
10971100

1101+
@set_module("pandas.api.types")
10981102
def is_float(obj: object) -> bool:
10991103
"""
11001104
Return True if given object is float.
@@ -1128,6 +1132,7 @@ def is_float(obj: object) -> bool:
11281132
return util.is_float_object(obj)
11291133

11301134

1135+
@set_module("pandas.api.types")
11311136
def is_integer(obj: object) -> bool:
11321137
"""
11331138
Return True if given object is integer.
@@ -1172,6 +1177,7 @@ def is_int_or_none(obj) -> bool:
11721177
return obj is None or util.is_integer_object(obj)
11731178

11741179

1180+
@set_module("pandas.api.types")
11751181
def is_bool(obj: object) -> bool:
11761182
"""
11771183
Return True if given object is boolean.
@@ -1202,6 +1208,7 @@ def is_bool(obj: object) -> bool:
12021208
return util.is_bool_object(obj)
12031209

12041210

1211+
@set_module("pandas.api.types")
12051212
def is_complex(obj: object) -> bool:
12061213
"""
12071214
Return True if given object is complex.
@@ -1237,6 +1244,7 @@ cpdef bint is_decimal(object obj):
12371244
return isinstance(obj, Decimal)
12381245

12391246

1247+
@set_module("pandas.api.types")
12401248
def is_list_like(obj: object, allow_sets: bool = True) -> bool:
12411249
"""
12421250
Check if the object is list-like.
@@ -1520,6 +1528,7 @@ cdef object _try_infer_map(object dtype):
15201528
return None
15211529

15221530

1531+
@set_module("pandas.api.types")
15231532
def infer_dtype(value: object, skipna: bool = True) -> str:
15241533
"""
15251534
Return a string label of the type of the elements in a list-like input.

pandas/core/dtypes/common.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from pandas._libs.tslibs import conversion
2424
from pandas.errors import Pandas4Warning
25+
from pandas.util._decorators import set_module
2526
from pandas.util._exceptions import find_stack_level
2627

2728
from pandas.core.dtypes.base import _registry as registry
@@ -138,6 +139,7 @@ def _classes_and_not_datetimelike(*klasses) -> Callable:
138139
)
139140

140141

142+
@set_module("pandas.api.types")
141143
def is_object_dtype(arr_or_dtype) -> bool:
142144
"""
143145
Check whether an array-like or dtype is of the object dtype.
@@ -183,6 +185,7 @@ def is_object_dtype(arr_or_dtype) -> bool:
183185
return _is_dtype_type(arr_or_dtype, classes(np.object_))
184186

185187

188+
@set_module("pandas.api.types")
186189
def is_sparse(arr) -> bool:
187190
"""
188191
Check whether an array-like is a 1-D pandas sparse array.
@@ -282,6 +285,7 @@ def is_scipy_sparse(arr) -> bool:
282285
return _is_scipy_sparse(arr)
283286

284287

288+
@set_module("pandas.api.types")
285289
def is_datetime64_dtype(arr_or_dtype) -> bool:
286290
"""
287291
Check whether an array-like or dtype is of the datetime64 dtype.
@@ -323,6 +327,7 @@ def is_datetime64_dtype(arr_or_dtype) -> bool:
323327
return _is_dtype_type(arr_or_dtype, classes(np.datetime64))
324328

325329

330+
@set_module("pandas.api.types")
326331
def is_datetime64tz_dtype(arr_or_dtype) -> bool:
327332
"""
328333
Check whether an array-like or dtype is of a DatetimeTZDtype dtype.
@@ -384,6 +389,7 @@ def is_datetime64tz_dtype(arr_or_dtype) -> bool:
384389
return DatetimeTZDtype.is_dtype(arr_or_dtype)
385390

386391

392+
@set_module("pandas.api.types")
387393
def is_timedelta64_dtype(arr_or_dtype) -> bool:
388394
"""
389395
Check whether an array-like or dtype is of the timedelta64 dtype.
@@ -426,6 +432,7 @@ def is_timedelta64_dtype(arr_or_dtype) -> bool:
426432
return _is_dtype_type(arr_or_dtype, classes(np.timedelta64))
427433

428434

435+
@set_module("pandas.api.types")
429436
def is_period_dtype(arr_or_dtype) -> bool:
430437
"""
431438
Check whether an array-like or dtype is of the Period dtype.
@@ -479,6 +486,7 @@ def is_period_dtype(arr_or_dtype) -> bool:
479486
return PeriodDtype.is_dtype(arr_or_dtype)
480487

481488

489+
@set_module("pandas.api.types")
482490
def is_interval_dtype(arr_or_dtype) -> bool:
483491
"""
484492
Check whether an array-like or dtype is of the Interval dtype.
@@ -537,6 +545,7 @@ def is_interval_dtype(arr_or_dtype) -> bool:
537545
return IntervalDtype.is_dtype(arr_or_dtype)
538546

539547

548+
@set_module("pandas.api.types")
540549
def is_categorical_dtype(arr_or_dtype) -> bool:
541550
"""
542551
Check whether an array-like or dtype is of the Categorical dtype.
@@ -598,6 +607,7 @@ def is_string_or_object_np_dtype(dtype: np.dtype) -> bool:
598607
return dtype == object or dtype.kind in "SU"
599608

600609

610+
@set_module("pandas.api.types")
601611
def is_string_dtype(arr_or_dtype) -> bool:
602612
"""
603613
Check whether the provided array or dtype is of the string dtype.
@@ -650,6 +660,7 @@ def condition(dtype) -> bool:
650660
return _is_dtype(arr_or_dtype, condition)
651661

652662

663+
@set_module("pandas.api.types")
653664
def is_dtype_equal(source, target) -> bool:
654665
"""
655666
Check if two dtypes are equal.
@@ -714,6 +725,7 @@ def is_dtype_equal(source, target) -> bool:
714725
return False
715726

716727

728+
@set_module("pandas.api.types")
717729
def is_integer_dtype(arr_or_dtype) -> bool:
718730
"""
719731
Check whether the provided array or dtype is of an integer dtype.
@@ -780,6 +792,7 @@ def is_integer_dtype(arr_or_dtype) -> bool:
780792
)
781793

782794

795+
@set_module("pandas.api.types")
783796
def is_signed_integer_dtype(arr_or_dtype) -> bool:
784797
"""
785798
Check whether the provided array or dtype is of a signed integer dtype.
@@ -848,6 +861,7 @@ def is_signed_integer_dtype(arr_or_dtype) -> bool:
848861
)
849862

850863

864+
@set_module("pandas.api.types")
851865
def is_unsigned_integer_dtype(arr_or_dtype) -> bool:
852866
"""
853867
Check whether the provided array or dtype is of an unsigned integer dtype.
@@ -907,6 +921,7 @@ def is_unsigned_integer_dtype(arr_or_dtype) -> bool:
907921
)
908922

909923

924+
@set_module("pandas.api.types")
910925
def is_int64_dtype(arr_or_dtype) -> bool:
911926
"""
912927
Check whether the provided array or dtype is of the int64 dtype.
@@ -980,6 +995,7 @@ def is_int64_dtype(arr_or_dtype) -> bool:
980995
return _is_dtype_type(arr_or_dtype, classes(np.int64))
981996

982997

998+
@set_module("pandas.api.types")
983999
def is_datetime64_any_dtype(arr_or_dtype) -> bool:
9841000
"""
9851001
Check whether the provided array or dtype is of the datetime64 dtype.
@@ -1042,6 +1058,7 @@ def is_datetime64_any_dtype(arr_or_dtype) -> bool:
10421058
)
10431059

10441060

1061+
@set_module("pandas.api.types")
10451062
def is_datetime64_ns_dtype(arr_or_dtype) -> bool:
10461063
"""
10471064
Check whether the provided array or dtype is of the datetime64[ns] dtype.
@@ -1097,6 +1114,7 @@ def is_datetime64_ns_dtype(arr_or_dtype) -> bool:
10971114
)
10981115

10991116

1117+
@set_module("pandas.api.types")
11001118
def is_timedelta64_ns_dtype(arr_or_dtype) -> bool:
11011119
"""
11021120
Check whether the provided array or dtype is of the timedelta64[ns] dtype.
@@ -1224,6 +1242,7 @@ def needs_i8_conversion(dtype: DtypeObj | None) -> bool:
12241242
return isinstance(dtype, (PeriodDtype, DatetimeTZDtype))
12251243

12261244

1245+
@set_module("pandas.api.types")
12271246
def is_numeric_dtype(arr_or_dtype) -> bool:
12281247
"""
12291248
Check whether the provided array or dtype is of a numeric dtype.
@@ -1278,6 +1297,7 @@ def is_numeric_dtype(arr_or_dtype) -> bool:
12781297
)
12791298

12801299

1300+
@set_module("pandas.api.types")
12811301
def is_any_real_numeric_dtype(arr_or_dtype) -> bool:
12821302
"""
12831303
Check whether the provided array or dtype is of a real number dtype.
@@ -1321,6 +1341,7 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool:
13211341
)
13221342

13231343

1344+
@set_module("pandas.api.types")
13241345
def is_float_dtype(arr_or_dtype) -> bool:
13251346
"""
13261347
Check whether the provided array or dtype is of a float dtype.
@@ -1368,6 +1389,7 @@ def is_float_dtype(arr_or_dtype) -> bool:
13681389
)
13691390

13701391

1392+
@set_module("pandas.api.types")
13711393
def is_bool_dtype(arr_or_dtype) -> bool:
13721394
"""
13731395
Check whether the provided array or dtype is of a boolean dtype.
@@ -1455,6 +1477,7 @@ def is_1d_only_ea_dtype(dtype: DtypeObj | None) -> bool:
14551477
return isinstance(dtype, ExtensionDtype) and not dtype._supports_2d
14561478

14571479

1480+
@set_module("pandas.api.types")
14581481
def is_extension_array_dtype(arr_or_dtype) -> bool:
14591482
"""
14601483
Check if an object is a pandas extension array type.
@@ -1532,6 +1555,7 @@ def is_ea_or_datetimelike_dtype(dtype: DtypeObj | None) -> bool:
15321555
return isinstance(dtype, ExtensionDtype) or (lib.is_np_dtype(dtype, "mM"))
15331556

15341557

1558+
@set_module("pandas.api.types")
15351559
def is_complex_dtype(arr_or_dtype) -> bool:
15361560
"""
15371561
Check whether the provided array or dtype is of a complex dtype.
@@ -1794,6 +1818,7 @@ def validate_all_hashable(*args, error_name: str | None = None) -> None:
17941818
raise TypeError("All elements must be hashable")
17951819

17961820

1821+
@set_module("pandas.api.types")
17971822
def pandas_dtype(dtype) -> DtypeObj:
17981823
"""
17991824
Convert input into a pandas only dtype object or a numpy dtype object.

pandas/core/dtypes/concat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313

1414
from pandas._libs import lib
15+
from pandas.util._decorators import set_module
1516

1617
from pandas.core.dtypes.astype import astype_array
1718
from pandas.core.dtypes.cast import (
@@ -168,6 +169,7 @@ def _get_result_dtype(
168169
return any_ea, kinds, target_dtype
169170

170171

172+
@set_module("pandas.api.types")
171173
def union_categoricals(
172174
to_union, sort_categories: bool = False, ignore_order: bool = False
173175
) -> Categorical:

pandas/core/dtypes/inference.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numpy as np
1515

1616
from pandas._libs import lib
17+
from pandas.util._decorators import set_module
1718

1819
if TYPE_CHECKING:
1920
from collections.abc import Hashable
@@ -35,6 +36,7 @@
3536
is_iterator = lib.is_iterator
3637

3738

39+
@set_module("pandas.api.types")
3840
def is_number(obj: object) -> TypeGuard[Number | np.number]:
3941
"""
4042
Check if the object is a number.
@@ -101,6 +103,7 @@ def iterable_not_string(obj: object) -> bool:
101103
return isinstance(obj, abc.Iterable) and not isinstance(obj, str)
102104

103105

106+
@set_module("pandas.api.types")
104107
def is_file_like(obj: object) -> bool:
105108
"""
106109
Check if the object is a file-like object.
@@ -148,6 +151,7 @@ def is_file_like(obj: object) -> bool:
148151
return bool(hasattr(obj, "__iter__"))
149152

150153

154+
@set_module("pandas.api.types")
151155
def is_re(obj: object) -> TypeGuard[Pattern]:
152156
"""
153157
Check if the object is a regex pattern instance.
@@ -184,6 +188,7 @@ def is_re(obj: object) -> TypeGuard[Pattern]:
184188
return isinstance(obj, Pattern)
185189

186190

191+
@set_module("pandas.api.types")
187192
def is_re_compilable(obj: object) -> bool:
188193
"""
189194
Check if the object can be compiled into a regex pattern instance.
@@ -218,6 +223,7 @@ def is_re_compilable(obj: object) -> bool:
218223
return True
219224

220225

226+
@set_module("pandas.api.types")
221227
def is_array_like(obj: object) -> bool:
222228
"""
223229
Check if the object is array-like.
@@ -297,6 +303,7 @@ def is_nested_list_like(obj: object) -> bool:
297303
)
298304

299305

306+
@set_module("pandas.api.types")
300307
def is_dict_like(obj: object) -> bool:
301308
"""
302309
Check if the object is dict-like.
@@ -339,6 +346,7 @@ def is_dict_like(obj: object) -> bool:
339346
)
340347

341348

349+
@set_module("pandas.api.types")
342350
def is_named_tuple(obj: object) -> bool:
343351
"""
344352
Check if the object is a named tuple.
@@ -376,6 +384,7 @@ def is_named_tuple(obj: object) -> bool:
376384
return isinstance(obj, abc.Sequence) and hasattr(obj, "_fields")
377385

378386

387+
@set_module("pandas.api.types")
379388
def is_hashable(obj: object) -> TypeGuard[Hashable]:
380389
"""
381390
Return True if hash(obj) will succeed, False otherwise.

pandas/core/indexers/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313

1414
from pandas._libs import lib
15+
from pandas.util._decorators import set_module
1516

1617
from pandas.core.dtypes.common import (
1718
is_array_like,
@@ -417,6 +418,7 @@ def unpack_tuple_and_ellipses(item: tuple):
417418
# Public indexer validation
418419

419420

421+
@set_module("pandas.api.indexers")
420422
def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any:
421423
"""
422424
Check if `indexer` is a valid array indexer for `array`.

pandas/core/interchange/from_dataframe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas._config import using_string_dtype
1313

1414
from pandas.compat._optional import import_optional_dependency
15+
from pandas.util._decorators import set_module
1516

1617
import pandas as pd
1718
from pandas.core.interchange.dataframe_protocol import (
@@ -34,6 +35,7 @@
3435
}
3536

3637

38+
@set_module("pandas.api.interchange")
3739
def from_dataframe(df, allow_copy: bool = True) -> pd.DataFrame:
3840
"""
3941
Build a ``pd.DataFrame`` from any DataFrame supporting the interchange protocol.

0 commit comments

Comments
 (0)