Skip to content

fix the string datatype #8

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

Closed
Closed
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
12 changes: 10 additions & 2 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
pa_version_under10p1,
)
from pandas.compat.numpy import function as nv
from pandas.util._decorators import doc
from pandas.util._decorators import (
doc,
set_module,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.base import (
Expand Down Expand Up @@ -86,6 +89,7 @@
from pandas import Series


@set_module("pandas")
@register_extension_dtype
class StringDtype(StorageExtensionDtype):
"""
Expand Down Expand Up @@ -374,6 +378,7 @@ def __from_arrow__(
return new_string_array


@set_module("pandas")
class BaseStringArray(ExtensionArray):
"""
Mixin class for StringArray, ArrowStringArray.
Expand Down Expand Up @@ -532,6 +537,8 @@ def _str_map_nan_semantics(

# error: Definition of "_concat_same_type" in base class "NDArrayBacked" is
# incompatible with definition in base class "ExtensionArray"


class StringArray(BaseStringArray, NumpyExtensionArray): # type: ignore[misc]
"""
Extension array for string data.
Expand Down Expand Up @@ -721,7 +728,8 @@ def __arrow_array__(self, type=None):
values[self.isna()] = None
return pa.array(values, type=type, from_pandas=True)

def _values_for_factorize(self) -> tuple[np.ndarray, libmissing.NAType | float]: # type: ignore[override]
# type: ignore[override]
def _values_for_factorize(self) -> tuple[np.ndarray, libmissing.NAType | float]:
arr = self._ndarray

return arr, self.dtype.na_value
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,7 @@ def test_set_module():
assert pd.Period.__module__ == "pandas"
assert pd.Timestamp.__module__ == "pandas"
assert pd.Timedelta.__module__ == "pandas"
assert pd.StringDtype.__module__ == "pandas"
assert pd.BaseStringArray.__module__ == "pandas"
assert pd.StringArrayNumpySemantics.___module__ == "pandas"
assert pd.StringArray.__module__ == "pandas"