Skip to content

Commit caf9134

Browse files
authored
gh-483: Changed the return type to dict in to_dict (#518)
* Changed the return type to dict * updated the dict argument * Corrections changed the Series.to_dict
1 parent 576ea74 commit caf9134

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
474474
def items(self) -> Iterable[tuple[Hashable, S1]]: ...
475475
def keys(self) -> list: ...
476476
@overload
477-
def to_dict(self) -> dict[Hashable, S1]: ...
477+
def to_dict(self) -> dict[Any, S1]: ...
478478
@overload
479479
def to_dict(self, into: type[Mapping] | Mapping) -> Mapping[Hashable, S1]: ...
480480
def to_frame(self, name: object | None = ...) -> DataFrame: ...

tests/test_series.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Any,
99
Dict,
1010
Generic,
11-
Hashable,
1211
Iterable,
1312
Iterator,
1413
List,
@@ -997,7 +996,7 @@ def test_types_to_list() -> None:
997996

998997
def test_types_to_dict() -> None:
999998
s = pd.Series(["a", "b", "c"], dtype=str)
1000-
assert_type(s.to_dict(), Dict[Hashable, str])
999+
assert_type(s.to_dict(), Dict[Any, str])
10011000

10021001

10031002
def test_categorical_codes():
@@ -1377,3 +1376,11 @@ def func() -> MySeries[float]:
13771376
return MySeries[float]([1, 2, 3])
13781377

13791378
func()
1379+
1380+
1381+
def test_change_to_dict_return_type() -> None:
1382+
id = [1, 2, 3]
1383+
value = ["a", "b", "c"]
1384+
df = pd.DataFrame(zip(id, value), columns=["id", "value"])
1385+
fd = df.set_index("id")["value"].to_dict()
1386+
check(assert_type(fd, Dict[Any, Any]), dict)

0 commit comments

Comments
 (0)