Skip to content
Open
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
4 changes: 2 additions & 2 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
cls,
data: (
np_2darray
| Sequence[SequenceNotStr]
| Sequence[Mapping[str, Any]]
| Iterator[SequenceNotStr]
| Iterator[Mapping[str, Any]]
| Mapping[str, Any]
| Mapping[str, SequenceNotStr[Any]]
),
Expand Down
18 changes: 18 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4710,6 +4710,15 @@ def test_from_records() -> None:
pd.DataFrame,
)

# testing with an iterator of tuples
check(
assert_type(
pd.DataFrame.from_records(iter(data_tuples), columns=["id", "name"]),
pd.DataFrame,
),
pd.DataFrame,
)

# testing with pd.Index as columns parameter
check(
assert_type(
Expand Down Expand Up @@ -4739,6 +4748,15 @@ def test_from_records() -> None:
pd.DataFrame,
)

# test with an iterator of dictionaries
check(
assert_type(
pd.DataFrame.from_records(iter(data_dict_list), columns=["id", "name"]),
pd.DataFrame,
),
pd.DataFrame,
)

# test with single dictionary
data_single_dict = {"id": 1, "name": "a"}
check(
Expand Down