-
-
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
Changes from all commits
00811a1
e5e86ce
ff795e0
b4687df
677fb69
0748063
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 |
---|---|---|
|
@@ -215,9 +215,7 @@ def test_roundtrip_empty(self, orient, convert_axes): | |
idx = pd.Index([], dtype=(float if convert_axes else object)) | ||
expected = DataFrame(index=idx, columns=idx) | ||
elif orient in ["index", "columns"]: | ||
# TODO: this condition is probably a bug | ||
idx = pd.Index([], dtype=(float if convert_axes else object)) | ||
expected = DataFrame(columns=idx) | ||
expected = DataFrame() | ||
else: | ||
expected = empty_frame.copy() | ||
|
||
|
@@ -651,11 +649,9 @@ def test_series_roundtrip_empty(self, orient): | |
data = empty_series.to_json(orient=orient) | ||
result = read_json(data, typ="series", orient=orient) | ||
|
||
expected = empty_series | ||
if orient in ("values", "records"): | ||
expected = expected.reset_index(drop=True) | ||
else: | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. any reason to change 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. No reason, my fingers must have liked np.float64 better than float in this case :-) |
||
|
||
tm.assert_series_equal(result, expected) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,35 +93,34 @@ def test_unparsable_strings_with_dt64_dtype(self): | |
Series(np.array(vals, dtype=object), dtype="datetime64[ns]") | ||
|
||
@pytest.mark.parametrize( | ||
"constructor,check_index_type", | ||
"constructor", | ||
[ | ||
# NOTE: some overlap with test_constructor_empty but that test does not | ||
# test for None or an empty generator. | ||
# test_constructor_pass_none tests None but only with the index also | ||
# passed. | ||
(lambda idx: Series(index=idx), True), | ||
(lambda idx: Series(None, index=idx), True), | ||
(lambda idx: Series({}, index=idx), False), # creates an Index[object] | ||
(lambda idx: Series((), index=idx), True), | ||
(lambda idx: Series([], index=idx), True), | ||
(lambda idx: Series((_ for _ in []), index=idx), True), | ||
(lambda idx: Series(data=None, index=idx), True), | ||
(lambda idx: Series(data={}, index=idx), False), # creates an Index[object] | ||
(lambda idx: Series(data=(), index=idx), True), | ||
(lambda idx: Series(data=[], index=idx), True), | ||
(lambda idx: Series(data=(_ for _ in []), index=idx), True), | ||
(lambda idx: Series(index=idx)), | ||
(lambda idx: Series(None, index=idx)), | ||
(lambda idx: Series({}, index=idx)), | ||
(lambda idx: Series((), index=idx)), | ||
(lambda idx: Series([], index=idx)), | ||
(lambda idx: Series((_ for _ in []), index=idx)), | ||
(lambda idx: Series(data=None, index=idx)), | ||
(lambda idx: Series(data={}, index=idx)), | ||
(lambda idx: Series(data=(), index=idx)), | ||
(lambda idx: Series(data=[], index=idx)), | ||
(lambda idx: Series(data=(_ for _ in []), index=idx)), | ||
], | ||
) | ||
@pytest.mark.parametrize("empty_index", [None, []]) | ||
def test_empty_constructor(self, constructor, check_index_type, empty_index): | ||
# TODO: share with frame test of the same name | ||
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) | ||
Comment on lines
+116
to
+123
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. nice, lovely simplification here! |
||
|
||
def test_invalid_dtype(self): | ||
# GH15520 | ||
|
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.