-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Replace internal use of loc with reindex in DataFrame append #26022
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26022 +/- ##
==========================================
- Coverage 91.82% 91.81% -0.01%
==========================================
Files 175 175
Lines 52551 52551
==========================================
- Hits 48256 48252 -4
- Misses 4295 4299 +4
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26022 +/- ##
==========================================
- Coverage 91.82% 91.82% -0.01%
==========================================
Files 175 175
Lines 52539 52539
==========================================
- Hits 48246 48242 -4
- Misses 4293 4297 +4
Continue to review full report at Codecov.
|
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.
always write tests first; how else would know if this works?
Sorry about that. In progress. |
1bce70f
to
47de400
Compare
result = df.append(dicts, ignore_index=True, sort=True) | ||
expected = df.append(DataFrame(dicts), ignore_index=True, sort=True) | ||
assert_frame_equal(result, expected) | ||
|
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.
Separate out test and reference issue number as a comment under test function def
.
47de400
to
4944b99
Compare
Prior to this fix, the test still would have passed, but a FutureWarning would have been thrown, and eventually a KeyError. Should I also throw in a check that a FutureWarning and/or KeyError is not thrown? |
Codecov Report
@@ Coverage Diff @@
## master #26022 +/- ##
==========================================
- Coverage 91.98% 91.97% -0.01%
==========================================
Files 175 175
Lines 52377 52377
==========================================
- Hits 48180 48176 -4
- Misses 4197 4201 +4
Continue to review full report at Codecov.
|
The way that the test is written is fine. Just need to separate it out. |
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -325,7 +325,7 @@ Indexing | |||
^^^^^^^^ | |||
|
|||
- Improved exception message when calling :meth:`DataFrame.iloc` with a list of non-numeric objects (:issue:`25753`). | |||
- | |||
- Bug in which :meth:`DataFrame.append` produced a warning indicating that a KeyError will be thrown in the future when the data to be appended contains new columns (:issue:`22252`). |
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.
double backticks on KeyError. make this clear that this warning should not have been shown.
@@ -167,6 +167,15 @@ def test_append_list_of_series_dicts(self): | |||
expected = df.append(DataFrame(dicts), ignore_index=True, sort=True) | |||
assert_frame_equal(result, expected) | |||
|
|||
# GH22252 |
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.
make this a new test
f050f5f
to
9ce63ff
Compare
9ce63ff
to
96490c4
Compare
Anything else to do here? |
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.
test comment, ping on green.
df = DataFrame(np.random.randn(5, 4), | ||
columns=['foo', 'bar', 'baz', 'qux']) | ||
|
||
dicts = [{'foo': 9}, {'bar': 10}] |
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 put an assert_produces_warning(None) around this
5f1ac55
to
f7d372d
Compare
lgtm. can you merge master; ping on green. |
f7d372d
to
ff96e0c
Compare
All green! |
thanks @cbertinato |
The issue here was that the DataFrame append method was using .loc, which only throws a warning now, but would eventually throw a KeyError whenever that went into effect. Just swapped out that use of .loc for .reindex.
git diff upstream/master -u -- "*.py" | flake8 --diff