Skip to content

Conversation

terencehonles
Copy link

  • Tests added: Please use assert_type() to assert the type of any return value

@cmp0xff
Copy link
Contributor

cmp0xff commented Sep 23, 2025

Hi @terencehonles , thank you for the proposal. However, according to the Pandas documentation, the data parameter in DataFrame.from_records accepts Sequences, not Iterables. Could you please raise an Issue or Pull Request in pandas-dev/pandas regarding the documentation?

@terencehonles
Copy link
Author

I'm not sure if I have time to follow up right now. I opened this PR because mypy is now complaining about some existing code I have (which I have silenced with an ignore statement). This is the pandas implementation and it does handle an iterator https://github.com/pandas-dev/pandas/blob/f6fa9b679006d08fa99d8c2b6dbd834ec60875d6/pandas/core/frame.py#L2240-L2263.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Sep 24, 2025

@terencehonles the docs are updated, so now @cmp0xff can review this PR and provide any feedback

Copy link
Contributor

@cmp0xff cmp0xff left a comment

Choose a reason for hiding this comment

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

The changes are now in accordance with the Pandas documentation.

One minor comment: the idea in L4702-L4711 seems to be duplicated by the code snippet below. Could you remove the latter? Thanks.

# Testing with list of tuples (instead of structured array for type compatibility)
data_array_tuples = [(1, "a"), (2, "b")]
check(
assert_type(
pd.DataFrame.from_records(data_array_tuples, columns=["id", "name"]),
pd.DataFrame,
),
pd.DataFrame,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants