Skip to content

feature #58141: Consistent naming conventions for string dtype aliases #61651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@
# let init-time option registration happen
import pandas.core.config_init # pyright: ignore[reportUnusedImport] # noqa: F401

# Import the new factory functions
from pandas.core.dtypes.factory import (
boolean,
categorical,
date,
datetime,
decimal,
duration,
floating,
integer,
interval,
list,
map,
period,
sparse,
string,
struct,
)

from pandas.core.api import (
# dtype
ArrowDtype,
Expand Down Expand Up @@ -281,24 +300,35 @@
"array",
"arrays",
"bdate_range",
"boolean",
"categorical",
"concat",
"crosstab",
"cut",
"date",
"date_range",
"datetime",
"decimal",
"describe_option",
"duration",
"errors",
"eval",
"factorize",
"floating",
"from_dummies",
"get_dummies",
"get_option",
"infer_freq",
"integer",
"interval",
"interval_range",
"io",
"isna",
"isnull",
"json_normalize",
"list",
"lreshape",
"map",
"melt",
"merge",
"merge_asof",
Expand All @@ -308,6 +338,7 @@
"offsets",
"option_context",
"options",
"period",
"period_range",
"pivot",
"pivot_table",
Expand Down Expand Up @@ -337,6 +368,9 @@
"set_eng_float_format",
"set_option",
"show_versions",
"sparse",
"string",
"struct",
"test",
"testing",
"timedelta_range",
Expand Down
13 changes: 7 additions & 6 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
TYPE_CHECKING,
Any,
cast,
List,
)
import warnings
import zoneinfo
Expand Down Expand Up @@ -675,7 +676,7 @@ def _is_boolean(self) -> bool:

return is_bool_dtype(self.categories)

def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> DtypeObj | None:
# check if we have all categorical dtype with identical categories
if all(isinstance(x, CategoricalDtype) for x in dtypes):
first = dtypes[0]
Expand Down Expand Up @@ -966,7 +967,7 @@ def __setstate__(self, state) -> None:
self._tz = state["tz"]
self._unit = state["unit"]

def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> DtypeObj | None:
if all(isinstance(t, DatetimeTZDtype) and t.tz == self.tz for t in dtypes):
np_dtype = np.max([cast(DatetimeTZDtype, t).base for t in [self, *dtypes]])
unit = np.datetime_data(np_dtype)[0]
Expand Down Expand Up @@ -1479,7 +1480,7 @@ def __from_arrow__(self, array: pa.Array | pa.ChunkedArray) -> IntervalArray:
)
return IntervalArray._concat_same_type(results)

def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> DtypeObj | None:
if not all(isinstance(x, IntervalDtype) for x in dtypes):
return None

Expand Down Expand Up @@ -1677,7 +1678,7 @@ def from_numpy_dtype(cls, dtype: np.dtype) -> BaseMaskedDtype:
else:
raise NotImplementedError(dtype)

def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> DtypeObj | None:
# We unwrap any masked dtypes, find the common dtype we would use
# for that, then re-mask the result.
from pandas.core.dtypes.cast import find_common_type
Expand Down Expand Up @@ -2104,7 +2105,7 @@ def _subtype_with_str(self):
return type(self.fill_value)
return self.subtype

def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> DtypeObj | None:
# TODO for now only handle SparseDtypes and numpy dtypes => extend
# with other compatible extension dtypes
from pandas.core.dtypes.cast import np_find_common_type
Expand Down Expand Up @@ -2419,7 +2420,7 @@ def _is_boolean(self) -> bool:
"""
return pa.types.is_boolean(self.pyarrow_dtype)

def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> DtypeObj | None:
# We unwrap any masked dtypes, find the common dtype we would use
# for that, then re-mask the result.
# Mirrors BaseMaskedDtype
Expand Down
Loading
Loading