Skip to content

Conversation

cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Sep 24, 2025

This PR originates from pandas-dev/pandas-stubs#1376, where people recognised that DataFrame.from_records supports an Iterable of data (see below), which is not specified in the current documentation.

pandas/pandas/core/frame.py

Lines 2240 to 2263 in f6fa9b6

if is_iterator(data):
if nrows == 0:
return cls(index=index, columns=columns)
try:
first_row = next(data)
except StopIteration:
return cls(index=index, columns=columns)
dtype = None
if hasattr(first_row, "dtype") and first_row.dtype.names:
dtype = first_row.dtype
values = [first_row]
if nrows is None:
values += data
else:
values.extend(itertools.islice(data, nrows - 1))
if dtype is not None:
data = np.array(values, dtype=dtype)
else:
data = values

@mroeschke mroeschke added the Docs label Sep 24, 2025
@mroeschke mroeschke added this to the 3.0 milestone Sep 24, 2025
@mroeschke mroeschke merged commit 98c9c7f into pandas-dev:main Sep 24, 2025
46 of 47 checks passed
@mroeschke
Copy link
Member

Thanks @cmp0xff

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

Successfully merging this pull request may close these issues.

2 participants