Skip to content
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

added pyarrow/numpy dtype literals and allowed str | DtypeObj as input for Series.astype #756

Merged
merged 14 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 1 addition & 2 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ FloatDtypeArg: TypeAlias = (
| Literal["d", "f8", "float64", "double", "float_"]
# https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.longdouble
| type[np.longdouble]
| Literal["g", "f16", "float96", "float128", "longdouble", "longfloat"]
| Literal["g", "f16", "float128", "longdouble", "longfloat"]
# PyArrow floating point types and their string aliases
| Literal[
"float[pyarrow]",
Expand All @@ -212,7 +212,6 @@ ComplexDtypeArg: TypeAlias = (
| Literal[
"G",
"c32",
"complex192",
"complex256",
"clongdouble",
"clongfloat",
Expand Down
31 changes: 9 additions & 22 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_types_init() -> None:
pd.Series(1)
pd.Series((1, 2, 3))
pd.Series(np.array([1, 2, 3]))
pd.Series(data=[1, 2, 3, 4], name="pd.Series")
pd.Series(data=[1, 2, 3, 4], name="series")
pd.Series(data=[1, 2, 3, 4], dtype=np.int8)
pd.Series(data={"row1": [1, 2], "row2": [3, 4]})
pd.Series(data=[1, 2, 3, 4], index=[4, 3, 2, 1], copy=True)
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_types_select() -> None:
s = pd.Series(data={"row1": 1, "row2": 2})
with pytest_warns_bounded(
FutureWarning,
"pd.Series.__getitem__ treating keys as positions is deprecated",
"Series.__getitem__ treating keys as positions is deprecated",
lower="2.0.99",
):
s[0]
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_types_fillna() -> None:
check(assert_type(s.fillna(0, axis="index"), pd.Series), pd.Series)
with pytest_warns_bounded(
FutureWarning,
"pd.Series.fillna with 'method' is deprecated",
"Series.fillna with 'method' is deprecated",
lower="2.0.99",
):
check(assert_type(s.fillna(method="backfill", axis=0), pd.Series), pd.Series)
Expand Down Expand Up @@ -1761,7 +1761,6 @@ def test_change_to_dict_return_type() -> None:
# numpy int64
(np.int_, np.int_),
("int_", np.int_),
("int0", np.int_),
("long", np.int_),
("l", np.int_),
("int64", np.int64),
Expand All @@ -1773,6 +1772,7 @@ def test_change_to_dict_return_type() -> None:
# numpy signed pointer (platform dependent one of int[8,16,32,64])
(np.intp, np.intp),
("intp", np.intp),
("int0", np.intp),
("p", np.intp),
# pyarrow integer types
("int8[pyarrow]", int),
Expand Down Expand Up @@ -1815,7 +1815,6 @@ def test_change_to_dict_return_type() -> None:
# numpy uint64
(np.uint, np.uint),
("uint", np.uint),
("uint0", np.uint),
("ulong", np.uint),
("L", np.uint),
("uint64", np.uint64),
Expand All @@ -1827,6 +1826,7 @@ def test_change_to_dict_return_type() -> None:
# numpy unsigned pointer (platform dependent one of uint[8,16,32,64])
(np.uintp, np.uintp),
("uintp", np.uintp),
("uint0", np.uintp),
("P", np.uintp),
# pyarrow unsigned integer types
("uint8[pyarrow]", int),
Expand Down Expand Up @@ -1870,7 +1870,7 @@ def test_change_to_dict_return_type() -> None:
("longfloat", np.longdouble),
("g", np.longdouble),
("f16", np.longdouble),
("float96", np.longdouble), # NOTE: WINDOWS ONLY
# ("float96", np.longdouble), # NOTE: WINDOWS ONLY
randolf-scholz marked this conversation as resolved.
Show resolved Hide resolved
("float128", np.longdouble), # NOTE: UNIX ONLY
# pyarrow float32
("float32[pyarrow]", float),
Expand Down Expand Up @@ -1906,7 +1906,7 @@ def test_change_to_dict_return_type() -> None:
("longcomplex", np.clongdouble),
("G", np.clongdouble),
("c32", np.clongdouble),
("complex192", np.clongdouble), # NOTE: WINDOWS ONLY
# ("complex192", np.clongdouble), # NOTE: WINDOWS ONLY
randolf-scholz marked this conversation as resolved.
Show resolved Hide resolved
("complex256", np.clongdouble), # NOTE: UNIX ONLY
]

Expand Down Expand Up @@ -2109,11 +2109,6 @@ def test_astype_bool(cast_arg: BooleanDtypeArg, target_type: type) -> None:
def test_astype_int(cast_arg: IntDtypeArg, target_type: type) -> None:
s = pd.Series([1, 2, 3])

if platform.system() == "Windows":
# Different behavior for uint32, uint64 and uintp on Windows
if cast_arg in ["uint32", "uint64", "uintp"]:
pass

if cast_arg in (np.longlong, "longlong", "q"):
pytest.skip(
"longlong is bugged, for details, see"
Expand Down Expand Up @@ -2234,11 +2229,7 @@ def test_astype_uint(cast_arg: IntDtypeArg, target_type: type) -> None:
def test_astype_float(cast_arg: FloatDtypeArg, target_type: type) -> None:
s = pd.Series([1, 2, 3])

if platform.system() != "Windows" and cast_arg == "float96":
with pytest.raises(TypeError):
s.astype(cast_arg)
pytest.skip("Unix does not support float96")
if platform.system() == "Windows" and cast_arg == "float128":
if platform.system() == "Windows" and cast_arg in ("f16", "float128"):
with pytest.raises(TypeError):
s.astype(cast_arg)
pytest.skip("Windows does not support float128")
randolf-scholz marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -2293,11 +2284,7 @@ def test_astype_float(cast_arg: FloatDtypeArg, target_type: type) -> None:
def test_astype_complex(cast_arg: ComplexDtypeArg, target_type: type) -> None:
s = pd.Series([1, 2, 3])

if platform.system() != "Windows" and cast_arg == "complex192":
with pytest.raises(TypeError):
s.astype(cast_arg)
pytest.skip("Unix does not support complex192")
if platform.system() == "Windows" and cast_arg == "complex256":
if platform.system() == "Windows" and cast_arg in ("c32", "complex256"):
with pytest.raises(TypeError):
s.astype(cast_arg)
pytest.skip("Windows does not support complex256")
randolf-scholz marked this conversation as resolved.
Show resolved Hide resolved
Expand Down