Skip to content

Commit c74909e

Browse files
authored
allow a dict in DataFrame.astype() (#449)
* allow a dict in DataFrame.astype() * use mixed types in astype_dict test
1 parent 7802c69 commit c74909e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ class DataFrame(NDFrame, OpsMixin):
13571357
) -> DataFrame: ...
13581358
def astype(
13591359
self,
1360-
dtype: _str | Dtype | dict[_str, _str | Dtype] | Series,
1360+
dtype: _str | Dtype | Mapping[HashableT, _str | Dtype] | Series,
13611361
copy: _bool = ...,
13621362
errors: _str = ...,
13631363
) -> DataFrame: ...

tests/test_frame.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,14 @@ def test_axes_as_tuple() -> None:
20542054
check(assert_type(df, pd.DataFrame), pd.DataFrame)
20552055

20562056

2057+
def test_astype_dict() -> None:
2058+
# GH 447
2059+
df = pd.DataFrame({"a": [1, 2, 3], 43: [4, 5, 6]})
2060+
columns_types = {"a": "int", 43: "float"}
2061+
df = df.astype(columns_types)
2062+
check(assert_type(df, pd.DataFrame), pd.DataFrame)
2063+
2064+
20572065
def test_setitem_none() -> None:
20582066
df = pd.DataFrame(
20592067
{"A": [1, 2, 3], "B": ["abc", "def", "ghi"]}, index=["x", "y", "z"]

0 commit comments

Comments
 (0)