Skip to content

Commit 8cfa67d

Browse files
committed
add is_type function
1 parent d10e22a commit 8cfa67d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

spec/API_specification/dataframe_api/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"Float64",
3131
"Float32",
3232
"Bool",
33+
"is_dtype",
3334
]
3435

3536

@@ -177,3 +178,36 @@ class Float32:
177178

178179
class Bool:
179180
"""Boolean type with 8 bits of precision."""
181+
182+
183+
def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
184+
"""
185+
Returns a boolean indicating whether a provided dtype is of a specified data type “kind”.
186+
187+
Parameters
188+
----------
189+
dtype: Any
190+
The input dtype.
191+
kind: str
192+
data type kind.
193+
The function must return a boolean indicating whether
194+
the input dtype is of a specified data type kind.
195+
The following dtype kinds must be supported:
196+
- 'bool': boolean data type (Bool).
197+
- 'signed integer': signed integer data types (Int8, Int16, Int32, Int64).
198+
- 'unsigned integer': unsigned integer data types (UInt8, UInt16, UInt32, UInt64).
199+
- 'temporal': temporal data types (Date, Datetime, Duration).
200+
- 'string': string data type (String).
201+
- 'floating': floating-point data types (Float32, Float64).
202+
- 'integral': integer data types. Shorthand for ('signed integer', 'unsigned integer').
203+
- 'numeric': numeric data types. Shorthand for ('integral', 'floating').
204+
205+
If kind is a tuple, the tuple specifies a union of dtypes and/or kinds,
206+
and the function must return a boolean indicating whether the input dtype
207+
is either equal to a specified dtype or belongs to at least one specified
208+
data type kind.
209+
210+
Returns
211+
-------
212+
bool
213+
"""

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

3132
The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following
3233
methods and attributes:

0 commit comments

Comments
 (0)