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
2 changes: 2 additions & 0 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
np_2darray
| Sequence[SequenceNotStr]
| Sequence[Mapping[str, Any]]
| Iterator[SequenceNotStr]
| Iterator[Mapping[str, Any]]
Comment on lines 550 to +553
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sequence is a subset of Iterator. Also the type variable in SequenceNotStr does not have a default value, so pyright-strict would complain.

Suggested change
| Sequence[SequenceNotStr]
| Sequence[Mapping[str, Any]]
| Iterator[SequenceNotStr]
| Iterator[Mapping[str, Any]]
| Iterator[SequenceNotStr[Any]]
| Iterator[Mapping[str, Any]]

| Mapping[str, Any]
| Mapping[str, SequenceNotStr[Any]]
),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pandas = "2.3.3"
pyarrow = ">=10.0.1"
pytest = ">=8.4.2"
pyright = ">=1.1.407"
ty = ">=0.0.1a24"
ty = "0.0.1a25"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer version has been released

Suggested change
ty = "0.0.1a25"
ty = ">=0.0.1a26"

pyrefly = ">=0.38.2"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
Expand Down
18 changes: 13 additions & 5 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4729,20 +4729,19 @@ def test_from_records() -> None:
pd.DataFrame,
)

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

# Testing with list of tuples (instead of structured array for type compatibility)
data_array_tuples = [(1, "a"), (2, "b")]
# testing with pd.Index as columns parameter
check(
assert_type(
pd.DataFrame.from_records(data_array_tuples, columns=["id", "name"]),
pd.DataFrame.from_records(data_tuples, columns=pd.Index(["id", "name"])),
pd.DataFrame,
),
pd.DataFrame,
Expand All @@ -4758,6 +4757,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