Skip to content

Commit a11a96a

Browse files
committed
numpy ravel with dataframe test GH#26247
Signed-off-by: Liang Yan <[email protected]>
1 parent 3ce07cb commit a11a96a

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

pandas/tests/frame/test_npfuncs.py

+100
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,103 @@ 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+
[1.32630178, -1.5509344, -0.44882555],
37+
[0.35882481, 1.26205496, -0.3703816],
38+
[-0.70546068, -0.72013531, 1.29900727],
39+
[1.45971404, 1.06565704, 0.26655015],
40+
[-0.88569331, 0.84377588, 0.84385505],
41+
[0.22467141, 0.53757261, -0.14684373],
42+
[-0.01709792, 0.1390986, 0.05081053],
43+
[-0.38753827, -0.18666106, 0.01021193],
44+
]
45+
)
46+
47+
result = np.ravel([DataFrame(batch.reshape(1, 3)) for batch in arr])
48+
expected = np.array(
49+
[
50+
0.11197053,
51+
0.44361564,
52+
-0.92589452,
53+
0.05883648,
54+
-0.00948922,
55+
-0.26469934,
56+
1.32630178,
57+
-1.5509344,
58+
-0.44882555,
59+
0.35882481,
60+
1.26205496,
61+
-0.3703816,
62+
-0.70546068,
63+
-0.72013531,
64+
1.29900727,
65+
1.45971404,
66+
1.06565704,
67+
0.26655015,
68+
-0.88569331,
69+
0.84377588,
70+
0.84385505,
71+
0.22467141,
72+
0.53757261,
73+
-0.14684373,
74+
-0.01709792,
75+
0.1390986,
76+
0.05081053,
77+
-0.38753827,
78+
-0.18666106,
79+
0.01021193,
80+
]
81+
)
82+
tm.assert_numpy_array_equal(result, expected)
83+
84+
result = np.ravel(DataFrame(arr[0].reshape(1, 3), columns=["x1", "x2", "x3"]))
85+
expected = np.array([0.11197053, 0.44361564, -0.92589452])
86+
tm.assert_numpy_array_equal(result, expected)
87+
88+
result = np.ravel(
89+
[
90+
DataFrame(batch.reshape(1, 3), columns=["x1", "x2", "x3"])
91+
for batch in arr
92+
]
93+
)
94+
expected = np.array(
95+
[
96+
0.11197053,
97+
0.44361564,
98+
-0.92589452,
99+
0.05883648,
100+
-0.00948922,
101+
-0.26469934,
102+
1.32630178,
103+
-1.5509344,
104+
-0.44882555,
105+
0.35882481,
106+
1.26205496,
107+
-0.3703816,
108+
-0.70546068,
109+
-0.72013531,
110+
1.29900727,
111+
1.45971404,
112+
1.06565704,
113+
0.26655015,
114+
-0.88569331,
115+
0.84377588,
116+
0.84385505,
117+
0.22467141,
118+
0.53757261,
119+
-0.14684373,
120+
-0.01709792,
121+
0.1390986,
122+
0.05081053,
123+
-0.38753827,
124+
-0.18666106,
125+
0.01021193,
126+
]
127+
)
128+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)