Skip to content

Commit 35261c0

Browse files
author
VibavariG
committed
Add test for DaaFrame.from_records()
1 parent a3d353f commit 35261c0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pandas/tests/frame/constructors/test_from_records.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,26 @@ def test_from_records_empty2(self):
469469

470470
alt = DataFrame(arr)
471471
tm.assert_frame_equal(alt, expected)
472+
473+
def test_from_records_structured_array(self):
474+
# GH 59717
475+
data = np.array(
476+
[
477+
("John", 25, "New York", 50000),
478+
("Jane", 30, "San Francisco", 75000),
479+
("Bob", 35, "Chicago", 65000),
480+
("Alice", 28, "Los Angeles", 60000),
481+
],
482+
dtype=[("name", "U10"), ("age", "i4"), ("city", "U15"), ("salary", "i4")],
483+
)
484+
485+
actual_result = DataFrame.from_records(data, columns=["name", "salary", "city"])
486+
487+
modified_data = {
488+
"name": ["John", "Jane", "Bob", "Alice"],
489+
"salary": np.array([50000, 75000, 65000, 60000], dtype="int32"),
490+
"city": ["New York", "San Francisco", "Chicago", "Los Angeles"],
491+
}
492+
expected_result = DataFrame(modified_data)
493+
494+
tm.assert_frame_equal(actual_result, expected_result)

0 commit comments

Comments
 (0)