Skip to content

Commit f491f37

Browse files
GH1358 Relax index type from DataFrame.from_records
1 parent 5768214 commit f491f37

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
549549
| Mapping[str, Any]
550550
| Mapping[str, SequenceNotStr[Any]]
551551
),
552-
index: str | SequenceNotStr[Hashable] | None = None,
553-
columns: ListLike | None = None,
552+
index: str | Axes | None = None,
554553
exclude: ListLike | None = None,
554+
columns: ListLike | None = None,
555555
coerce_float: bool = False,
556556
nrows: int | None = None,
557557
) -> Self: ...

tests/test_frame.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,6 +4815,40 @@ def test_from_records() -> None:
48154815
pd.DataFrame,
48164816
)
48174817

4818+
# GH1358
4819+
data, py_l = [[1, 2, 3], [4, 5, 6]], ["a", "b"]
4820+
4821+
check(
4822+
assert_type(pd.DataFrame.from_records(data, pd.Index(py_l)), pd.DataFrame),
4823+
pd.DataFrame,
4824+
)
4825+
check(
4826+
assert_type(pd.DataFrame.from_records(data, pd.Series(py_l)), pd.DataFrame),
4827+
pd.DataFrame,
4828+
)
4829+
check(
4830+
assert_type(
4831+
pd.DataFrame.from_records(data, pd.Series(py_l).array), pd.DataFrame
4832+
),
4833+
pd.DataFrame,
4834+
)
4835+
check(
4836+
assert_type(
4837+
pd.DataFrame.from_records(data, pd.Series(py_l).values), pd.DataFrame
4838+
),
4839+
pd.DataFrame,
4840+
)
4841+
check(
4842+
assert_type(pd.DataFrame.from_records(data, np.asarray(py_l)), pd.DataFrame),
4843+
pd.DataFrame,
4844+
)
4845+
check(
4846+
assert_type(
4847+
pd.DataFrame.from_records(data, np.asarray(py_l, np.str_)), pd.DataFrame
4848+
),
4849+
pd.DataFrame,
4850+
)
4851+
48184852

48194853
def test_frame_index_setter() -> None:
48204854
"""Test DataFrame.index setter property GH1366."""

0 commit comments

Comments
 (0)