Skip to content

Commit b03bb4f

Browse files
authored
Add an is_dtype function (#199)
1 parent adf2fe4 commit b03bb4f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

spec/API_specification/dataframe_api/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"Float64",
3333
"Float32",
3434
"Bool",
35+
"is_dtype",
3536
]
3637

3738

@@ -239,3 +240,35 @@ class Float32:
239240

240241
class Bool:
241242
"""Boolean type with 8 bits of precision."""
243+
244+
245+
def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
246+
"""
247+
Returns a boolean indicating whether a provided dtype is of a specified data type “kind”.
248+
249+
Parameters
250+
----------
251+
dtype: Any
252+
The input dtype.
253+
kind: str
254+
data type kind.
255+
The function must return a boolean indicating whether
256+
the input dtype is of a specified data type kind.
257+
The following dtype kinds must be supported:
258+
259+
- 'bool': boolean data type (Bool).
260+
- 'signed integer': signed integer data types (Int8, Int16, Int32, Int64).
261+
- 'unsigned integer': unsigned integer data types (UInt8, UInt16, UInt32, UInt64).
262+
- 'floating': floating-point data types (Float32, Float64).
263+
- 'integral': integer data types. Shorthand for ('signed integer', 'unsigned integer').
264+
- 'numeric': numeric data types. Shorthand for ('integral', 'floating').
265+
266+
If kind is a tuple, the tuple specifies a union of dtypes and/or kinds,
267+
and the function must return a boolean indicating whether the input dtype
268+
is either equal to a specified dtype or belongs to at least one specified
269+
data type kind.
270+
271+
Returns
272+
-------
273+
bool
274+
"""

spec/API_specification/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of objects and functions in the top-level namespace. The latter are:
2727
Float64
2828
Float32
2929
Bool
30+
is_dtype
3031
column_from_sequence
3132
column_from_1d_array
3233
dataframe_from_dict

0 commit comments

Comments
 (0)