Skip to content

Commit eebd967

Browse files
authored
numpy ravel with dataframe test GH#26247 (#52403)
Signed-off-by: Liang Yan <[email protected]>
1 parent 8e2746e commit eebd967

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pandas/tests/frame/test_npfuncs.py

+44
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,47 @@ def test_np_sqrt(self, float_frame):
2626
assert result.columns is float_frame.columns
2727

2828
tm.assert_frame_equal(result, float_frame.apply(np.sqrt))
29+
30+
def test_np_ravel(self):
31+
# GH26247
32+
arr = np.array(
33+
[
34+
[0.11197053, 0.44361564, -0.92589452],
35+
[0.05883648, -0.00948922, -0.26469934],
36+
]
37+
)
38+
39+
result = np.ravel([DataFrame(batch.reshape(1, 3)) for batch in arr])
40+
expected = np.array(
41+
[
42+
0.11197053,
43+
0.44361564,
44+
-0.92589452,
45+
0.05883648,
46+
-0.00948922,
47+
-0.26469934,
48+
]
49+
)
50+
tm.assert_numpy_array_equal(result, expected)
51+
52+
result = np.ravel(DataFrame(arr[0].reshape(1, 3), columns=["x1", "x2", "x3"]))
53+
expected = np.array([0.11197053, 0.44361564, -0.92589452])
54+
tm.assert_numpy_array_equal(result, expected)
55+
56+
result = np.ravel(
57+
[
58+
DataFrame(batch.reshape(1, 3), columns=["x1", "x2", "x3"])
59+
for batch in arr
60+
]
61+
)
62+
expected = np.array(
63+
[
64+
0.11197053,
65+
0.44361564,
66+
-0.92589452,
67+
0.05883648,
68+
-0.00948922,
69+
-0.26469934,
70+
]
71+
)
72+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)