-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
BUG: Preserve column names in DataFrame.from_records when nrows=0 #61143
base: main
Are you sure you want to change the base?
Changes from 4 commits
5dd7786
cc21929
e2fbceb
81ad960
5dcc1ac
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import pandas as pd | ||
def test_empty_df_preserve_col(): | ||
rows = [] | ||
df = pd.DataFrame.from_records(iter(rows), columns=['col_1', 'Col_2'], nrows=0) | ||
assert list(df.columns)==['col_1', 'Col_2'] | ||
assert len(df) == 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2780,6 +2780,12 @@ def test_construction_nan_value_timedelta64_dtype(self): | |
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_from_records_empty_iterator_with_preserve_columns(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. Can you move this test to |
||
|
||
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 you start the test with a comment referencing the issue. |
||
rows = [] | ||
df = pd.DataFrame.from_records(iter(rows), columns=["col_1", "Col_2"], nrows=0) | ||
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 you call the result |
||
assert list(df.columns) == ["col_1", "Col_2"] | ||
assert len(df) == 0 | ||
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. Instead of these two lines, can you check the entire result. expected = DataFrame(...)
tm.assert_frame_equal(result, expected)` |
||
|
||
class TestDataFrameConstructorIndexInference: | ||
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(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.
Can you follow the dev docs here: https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests
Namely, search the current tests for
from_records
and that should give a good indication of where to place this 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.
This file needs to be removed.