Skip to content

Commit 180d520

Browse files
feature #58141: Consistent naming conventions for string dtype aliases
Key implementation steps: - Created factory functions (string, datetime, integer, floating, decimal, boolean, list, categorical, interval, period, sparse, date, duration, map, struct) to generate pandas dtypes (e.g., StringDtype, Int64Dtype, ArrowDtype) based on parameters like backend, bits, unit, and precision. - Added support for both NumPy and PyArrow backends, enabling seamless switching (e.g., integer() returns Int64Dtype for NumPy or ArrowDtype(pa.int64()) for PyArrow). - Implemented parameter validation to ensure correct usage (e.g., validating mode in string() to be "string" or "binary", and unit in datetime() for NumPy). - Integrated PyArrow types for advanced dtypes (e.g., pa.float64(), pa.list_(), pa.map_()), supporting modern data processing frameworks. - Implemented comprehensive tests in test_factory.py to validate dtype creation across all functions, ensuring correct behavior for different backends, verifying string representations (e.g., "double[pyarrow]" for pa.float64()), and confirming proper error handling (e.g., raising ValueError for invalid inputs). - Addressed PyArrow compatibility by implementing correct method calls, such as using pa.bool_() for boolean dtypes, ensuring proper integration. This change simplifies dtype creation, reduces duplication, and ensures compatibility across backends, making it easier to extend support for new dtypes in the future. Co-authored-by: Pedro Santos <[email protected]>
1 parent 05f032c commit 180d520

File tree

3 files changed

+1073
-0
lines changed

3 files changed

+1073
-0
lines changed

pandas/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@
4242
# let init-time option registration happen
4343
import pandas.core.config_init # pyright: ignore[reportUnusedImport] # noqa: F401
4444

45+
# Import the new factory functions
46+
from pandas.core.dtypes.factory import (
47+
boolean,
48+
categorical,
49+
date,
50+
datetime,
51+
decimal,
52+
duration,
53+
floating,
54+
integer,
55+
interval,
56+
list,
57+
map,
58+
period,
59+
sparse,
60+
string,
61+
struct,
62+
)
63+
4564
from pandas.core.api import (
4665
# dtype
4766
ArrowDtype,
@@ -281,24 +300,35 @@
281300
"array",
282301
"arrays",
283302
"bdate_range",
303+
"boolean",
304+
"categorical",
284305
"concat",
285306
"crosstab",
286307
"cut",
308+
"date",
287309
"date_range",
310+
"datetime",
311+
"decimal",
288312
"describe_option",
313+
"duration",
289314
"errors",
290315
"eval",
291316
"factorize",
317+
"floating",
292318
"from_dummies",
293319
"get_dummies",
294320
"get_option",
295321
"infer_freq",
322+
"integer",
323+
"interval",
296324
"interval_range",
297325
"io",
298326
"isna",
299327
"isnull",
300328
"json_normalize",
329+
"list",
301330
"lreshape",
331+
"map",
302332
"melt",
303333
"merge",
304334
"merge_asof",
@@ -308,6 +338,7 @@
308338
"offsets",
309339
"option_context",
310340
"options",
341+
"period",
311342
"period_range",
312343
"pivot",
313344
"pivot_table",
@@ -337,6 +368,9 @@
337368
"set_eng_float_format",
338369
"set_option",
339370
"show_versions",
371+
"sparse",
372+
"string",
373+
"struct",
340374
"test",
341375
"testing",
342376
"timedelta_range",

0 commit comments

Comments
 (0)