Skip to content

Commit 2c603f6

Browse files
committed
fix: fix DataFrame.from_records with data as an iterator
1 parent 2f63354 commit 2c603f6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
544544
cls,
545545
data: (
546546
np_2darray
547-
| Sequence[SequenceNotStr]
548-
| Sequence[Mapping[str, Any]]
547+
| Iterator[SequenceNotStr]
548+
| Iterator[Mapping[str, Any]]
549549
| Mapping[str, Any]
550550
| Mapping[str, SequenceNotStr[Any]]
551551
),

tests/test_frame.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4710,6 +4710,15 @@ def test_from_records() -> None:
47104710
pd.DataFrame,
47114711
)
47124712

4713+
# testing with an iterator of tuples
4714+
check(
4715+
assert_type(
4716+
pd.DataFrame.from_records(iter(data_tuples), columns=["id", "name"]),
4717+
pd.DataFrame,
4718+
),
4719+
pd.DataFrame,
4720+
)
4721+
47134722
# testing with pd.Index as columns parameter
47144723
check(
47154724
assert_type(
@@ -4739,6 +4748,15 @@ def test_from_records() -> None:
47394748
pd.DataFrame,
47404749
)
47414750

4751+
# test with an iterator of dictionaries
4752+
check(
4753+
assert_type(
4754+
pd.DataFrame.from_records(iter(data_dict_list), columns=["id", "name"]),
4755+
pd.DataFrame,
4756+
),
4757+
pd.DataFrame,
4758+
)
4759+
47424760
# test with single dictionary
47434761
data_single_dict = {"id": 1, "name": "a"}
47444762
check(

0 commit comments

Comments
 (0)