-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: misleading error creating df from 2d array #42646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f4dc916
8d968f2
b189f10
4bb7180
b6381df
a09ac37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -615,6 +615,8 @@ def _extract_index(data) -> Index: | |
elif is_list_like(val) and getattr(val, "ndim", 1) == 1: | ||
have_raw_arrays = True | ||
raw_lengths.append(len(val)) | ||
elif isinstance(val, np.ndarray) and getattr(val, "ndim", 1) > 1: | ||
raise ValueError("Data must be 1-dimensional") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe something like "Per-column arrays must each be 1-dimensional"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amended |
||
|
||
if not indexes and not raw_lengths: | ||
raise ValueError("If using all scalar values, you must pass an index") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2530,6 +2530,19 @@ def test_from_2d_object_array_of_periods_or_intervals(self): | |
expected = DataFrame({0: pi, 1: ii, 2: pi, 3: ii}) | ||
tm.assert_frame_equal(df3, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"col_a, col_b", | ||
[ | ||
([[1], [2]], np.array([[1], [2]])), | ||
(np.array([[1], [2]]), [[1], [2]]), | ||
(np.array([[1], [2]]), np.array([[1], [2]])), | ||
], | ||
) | ||
def test_error_from_2darray(self, col_a, col_b): | ||
msg = "Data must be 1-dimensional" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably need to update the message here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. Updated the msg in test. |
||
with pytest.raises(ValueError, match=msg): | ||
DataFrame({"a": col_a, "b": col_b}) | ||
|
||
|
||
class TestDataFrameConstructorWithDtypeCoercion: | ||
def test_floating_values_integer_dtype(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the isinstance check the getattr can check can just be
val.ndim > 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amended