Skip to content

Commit 4702df7

Browse files
committed
Fix DataFrame.from_records type annotations and add pd.Index test- Change np.ndarray to np_2d_array for data parameter- Change SequenceNotStr[str] to ListLike for columns and exclude parameters- Add test case with pd.Index as columns parameterAddresses review feedback from Dr-Irv
1 parent 9877d2a commit 4702df7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,14 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
546546
def from_records(
547547
cls,
548548
data: (
549-
np.ndarray
549+
np_2d_array
550550
| Sequence[Any]
551551
| Iterable[Mapping[str, Any]]
552552
| Mapping[str, Sequence[Any]]
553553
),
554554
index: str | Sequence[str] | None = None,
555-
columns: SequenceNotStr[str] | None = None,
556-
exclude: SequenceNotStr[str] | None = None,
555+
columns: ListLike | None = None,
556+
exclude: ListLike | None = None,
557557
coerce_float: bool = False,
558558
nrows: int | None = None,
559559
) -> Self: ...

tests/test_frame.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,6 +4701,15 @@ def test_from_records() -> None:
47014701
pd.DataFrame,
47024702
)
47034703

4704+
# testing with pd.Index as columns parameter
4705+
check(
4706+
assert_type(
4707+
pd.DataFrame.from_records(data_tuples, columns=pd.Index(["id", "name"])),
4708+
pd.DataFrame,
4709+
),
4710+
pd.DataFrame,
4711+
)
4712+
47044713
# Testing with numpy structured array
47054714
data_array = np.array(
47064715
[(1, "a"), (2, "b"), (3, "c")],

0 commit comments

Comments
 (0)