-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG GH22858 When creating empty dataframe, only cast int to float if index given #22963
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
538fee0
BUG-22858 When creating empty dataframe, only cast int to float if in…
JustinZhengBC 9afeaeb
BUG-22858 Update whatsnew and make test more specific
JustinZhengBC c538730
BUG-22858 Clarify change in whatsnew and parametrize tests
JustinZhengBC 5e3a4ef
BUG-22858 Make requested changes
JustinZhengBC e7efa9d
BUG-22858 Fix whatsnew addition
JustinZhengBC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -798,25 +798,20 @@ def test_constructor_mrecarray(self): | |
result = DataFrame(mrecs, index=[1, 2]) | ||
assert_fr_equal(result, expected) | ||
|
||
def test_constructor_corner(self): | ||
def test_constructor_corner_shape(self): | ||
df = DataFrame(index=[]) | ||
assert df.values.shape == (0, 0) | ||
|
||
# empty but with specified dtype | ||
df = DataFrame(index=lrange(10), columns=['a', 'b'], dtype=object) | ||
assert df.values.dtype == np.object_ | ||
|
||
# does not error but ends up float | ||
df = DataFrame(index=lrange(10), columns=['a', 'b'], dtype=int) | ||
assert df.values.dtype == np.dtype('float64') | ||
|
||
# #1783 empty dtype object | ||
df = DataFrame({}, columns=['foo', 'bar']) | ||
assert df.values.dtype == np.object_ | ||
|
||
df = DataFrame({'b': 1}, index=lrange(10), columns=list('abc'), | ||
dtype=int) | ||
assert df.values.dtype == np.dtype('float64') | ||
@pytest.mark.parametrize("data, index, columns, dtype, expected", [ | ||
(None, lrange(10), ['a', 'b'], object, np.object_), | ||
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. can u rename ans -> expected |
||
(None, None, ['a', 'b'], 'int64', np.dtype('int64')), | ||
(None, lrange(10), ['a', 'b'], int, np.dtype('float64')), | ||
({}, None, ['foo', 'bar'], None, np.object_), | ||
({'b': 1}, lrange(10), list('abc'), int, np.dtype('float64')) | ||
]) | ||
def test_constructor_dtype(self, data, index, columns, dtype, expected): | ||
df = DataFrame(data, index, columns, dtype) | ||
assert df.values.dtype == expected | ||
|
||
def test_constructor_scalar_inference(self): | ||
data = {'int': 1, 'bool': True, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
put in the section itself, just below this (it’s a backward incompatible change)