-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Series/DataFrame from empty dict should have RangeIndex #52426
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
API: Series/DataFrame from empty dict should have RangeIndex #52426
Conversation
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.
Nice, thanks for the quick fix! Got a couple of little comments but looks good overall
expected = Index(keys, dtype="object", tupleize_cols=False) | ||
expected = Index(keys, tupleize_cols=False) if keys else RangeIndex(0) |
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.
any chance we could include this in the parametrisation, instead of introducing an if-else in the test?
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.
Yes, that would be better.
expected.index = expected.index.astype(float) | ||
expected = empty_series.reset_index(drop=True) | ||
if orient in ("split"): | ||
expected.index = expected.index.astype(np.float64) |
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.
any reason to change float
to np.float64
? (not an issue, just trying to understand)
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.
No reason, my fingers must have liked np.float64 better than float in this case :-)
def test_empty_constructor(self, constructor, empty_index): | ||
# GH 49573 (addition of empty_index parameter) | ||
expected = Series(index=empty_index) | ||
result = constructor(empty_index) | ||
|
||
assert result.dtype == object | ||
assert len(result.index) == 0 | ||
tm.assert_series_equal(result, expected, check_index_type=check_index_type) | ||
tm.assert_series_equal(result, expected, check_index_type=True) |
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.
nice, lovely simplification here!
[ | ||
({}, [], "index"), | ||
([{("a",): 1}, {("a",): 2}], [("a",)], "columns"), | ||
([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)], "columns"), |
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.
what happened to the ordereddict test case?
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.
Yeah, I've added it back in.
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.
LGTM. Merge when ready @MarcoGorelli
Small ping. |
Thanks @topper-123 |
…hould have RangeIndex
…dict should have RangeIndex) (#52578) Backport PR #52426: API: Series/DataFrame from empty dict should have RangeIndex Co-authored-by: Terji Petersen <[email protected]>
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.