Skip to content

Commit 7da086e

Browse files
committed

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from builtins import (
22
bool as _bool,
33
str as _str,
44
)
5+
from collections import defaultdict
56
from collections.abc import (
67
Callable,
78
Hashable,
@@ -395,6 +396,14 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
395396
na_value: Scalar = ...,
396397
) -> np.ndarray: ...
397398
@overload
399+
def to_dict(
400+
self,
401+
orient=...,
402+
*,
403+
into: type[defaultdict],
404+
index: Literal[True] = ...,
405+
) -> Never: ...
406+
@overload
398407
def to_dict(
399408
self,
400409
orient: Literal["records"],

tests/test_frame.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from collections import defaultdict
44
from collections.abc import (
5+
Callable,
56
Hashable,
67
Iterable,
78
Iterator,
@@ -20,7 +21,6 @@
2021
from typing import (
2122
TYPE_CHECKING,
2223
Any,
23-
Callable,
2424
Generic,
2525
TypedDict,
2626
TypeVar,
@@ -39,6 +39,7 @@
3939
)
4040
import pytest
4141
from typing_extensions import (
42+
Never,
4243
TypeAlias,
4344
assert_never,
4445
assert_type,
@@ -3650,6 +3651,15 @@ def test(mapping: Mapping) -> None: # pyright: ignore[reportUnusedFunction]
36503651
into=mapping # pyright: ignore[reportArgumentType,reportCallIssue]
36513652
)
36523653

3654+
assert_type(DF.to_dict(into=defaultdict), Never)
3655+
assert_type(DF.to_dict("records", into=defaultdict), Never)
3656+
assert_type(DF.to_dict("index", into=defaultdict), Never)
3657+
assert_type(DF.to_dict("dict", into=defaultdict), Never)
3658+
assert_type(DF.to_dict("list", into=defaultdict), Never)
3659+
assert_type(DF.to_dict("series", into=defaultdict), Never)
3660+
assert_type(DF.to_dict("split", into=defaultdict), Never)
3661+
assert_type(DF.to_dict("tight", into=defaultdict), Never)
3662+
36533663

36543664
def test_to_dict_into_defaultdict_any() -> None:
36553665
"""Test DataFrame.to_dict with `into=defaultdict[Any, list]`"""

0 commit comments

Comments
 (0)