-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Improve error message for DataFrame.from_dict when wrong orient is provided #47451
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 5 commits
7240eca
de3cc11
cc41d3a
bffe1c1
efcf89a
0ac0e7d
16ccf81
869d8bc
d47c818
4732c24
d34cc8d
4691aad
a2d6860
6b43dda
fd78ffd
be1fc49
928bdf7
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 |
---|---|---|
|
@@ -17,11 +17,6 @@ class TestFromDict: | |
# Note: these tests are specific to the from_dict method, not for | ||
# passing dictionaries to DataFrame.__init__ | ||
|
||
def test_from_dict_scalars_requires_index(self): | ||
msg = "If using all scalar values, you must pass an index" | ||
with pytest.raises(ValueError, match=msg): | ||
DataFrame.from_dict(OrderedDict([("b", 8), ("a", 5), ("a", 6)])) | ||
|
||
def test_constructor_list_of_odicts(self): | ||
data = [ | ||
OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]]), | ||
|
@@ -189,3 +184,13 @@ def test_frame_dict_constructor_empty_series(self): | |
# it works! | ||
DataFrame({"foo": s1, "bar": s2, "baz": s3}) | ||
DataFrame.from_dict({"foo": s1, "baz": s3, "bar": s2}) | ||
|
||
def test_from_dict_scalars_requires_index(self): | ||
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. Note: I moved this function down here, so that all functions that test exception behaviours are grouped together. Not sure if that complies to the guidelines, but it certainly seems better 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. Great! |
||
msg = "If using all scalar values, you must pass an index" | ||
with pytest.raises(ValueError, match=msg): | ||
DataFrame.from_dict(OrderedDict([("b", 8), ("a", 5), ("a", 6)])) | ||
|
||
def test_from_dict_orient_invalid(self): | ||
msg = "only recognize 'index', 'columns', or 'tight' for orient" | ||
with pytest.raises(ValueError, match=msg): | ||
DataFrame.from_dict({"foo": 1, "baz": 3, "bar": 2}, orient='abc') |
Uh oh!
There was an error while loading. Please reload this page.