-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: Unify .update to generic #23192
Conversation
Hello @h-vetinari! Thanks for updating the PR.
Comment last updated on November 11, 2018 at 10:14 Hours UTC |
16ca125
to
c6e9dfb
Compare
pandas/core/generic.py
Outdated
@@ -99,6 +99,32 @@ def _single_replace(self, to_replace, method, inplace, limit): | |||
return result | |||
|
|||
|
|||
def _update_column(this, that, overwrite=True, filter_func=None, | |||
raise_conflict=False): | |||
import pandas.core.computation.expressions as expressions |
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.
add a doc-string
pandas/core/generic.py
Outdated
@@ -99,6 +99,32 @@ def _single_replace(self, to_replace, method, inplace, limit): | |||
return result | |||
|
|||
|
|||
def _update_column(this, that, overwrite=True, filter_func=None, | |||
raise_conflict=False): |
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.
move this to pandas/core/missing.py
, you can de-privatize it and rename to update_array
pandas/core/generic.py
Outdated
@@ -99,6 +99,32 @@ def _single_replace(self, to_replace, method, inplace, limit): | |||
return result | |||
|
|||
|
|||
def _update_column(this, that, overwrite=True, filter_func=None, | |||
raise_conflict=False): |
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.
I think we have an issue, but pls create one to deprecate this arg and rename to errors=
(you can do that in the internal function and put a TODO in the external facing ones).
pandas/core/generic.py
Outdated
if updated is None: | ||
# don't overwrite Series unnecessarily | ||
return | ||
self._data._block.values = updated |
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 is SO unsafe, doesn't handle caching and is reaching into internals. Use self._update_inplace(updated)
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.
if updated is not None:
self._update_inplace(updated)
original object. | ||
overwrite : bool, default True | ||
How to handle non-NA values for overlapping keys: | ||
|
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 indicate with a versionadded tag what has changed compared to current
pandas/core/generic.py
Outdated
filter_func=filter_func, | ||
raise_conflict=raise_conflict) | ||
# don't overwrite columns unnecessarily | ||
if updated is None: |
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.
if updated is not None:
self[col] = updated
doc/source/whatsnew/v0.24.0.txt
Outdated
@@ -200,6 +200,7 @@ Other Enhancements | |||
- :meth:`Series.resample` and :meth:`DataFrame.resample` have gained the :meth:`Resampler.quantile` (:issue:`15023`). | |||
- :meth:`Index.to_frame` now supports overriding column name(s) (:issue:`22580`). | |||
- New attribute :attr:`__git_version__` will return git commit sha of current build (:issue:`21295`). | |||
- :meth:`Series.update` now supports the same keywords and functionality as :meth:`DataFrame.update` (:issue:`22358`) |
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 enumerate what has changed.
also have a look at #3025 |
@jreback
only got caught by the doctests. Are we fine with changing that? |
let's make first pass that doesn't change anything, xfail new tests if needed for #23192 (comment). I would try the approach for #3025 as an alternative |
Split off the dtype promotion tests for Series (which are already passing on master) off into a precursor: #23604 |
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.
@jreback
Incorporated your feedback for deprecating raise_conflict
, and fixed the dtype thing as well. PTAL
pandas/core/panel.py
Outdated
warnings.simplefilter("ignore", FutureWarning) | ||
# do not warn about constructing Panel when reindexing | ||
result = super(Panel, self).reindex(**kwargs) | ||
return result |
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.
I had no intention to add this warning filter here, but otherwise I cannot test the raise_conflict
deprecation for Panel
, as this warning was throwing me off from trying to catch the deprecation warning. If we don't care about testing that kwarg deprecation for Panel
, I can revert this change here.
A B | ||
0 1 4 | ||
1 2 500 | ||
2 3 6 |
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 isn't obvious from the diff (due to the code moving files), but now this keeps the dtype - yay!
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.
Forgot to mention this before.
""" | ||
updated = _update_array(this, that, overwrite=overwrite, | ||
filter_func=filter_func, errors=errors) | ||
return this if updated is None else updated |
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.
@jreback
You asked me to move the function here and make it public as update_array
. This had the problem that it had the fallback of returning None
in case there were no changes, which is necessary to avoid pointlessly updating the columns in NDFrame.update
.
However, I was not comfortable with a public function having such unexpected behaviour, so I made the function I used originally private again (but still in core.missing
) and just made a thin wrapper around it public, that only filters out the None-returning case.
@h-vetinari I'm canceling the the old azure builds for this PR as you add new commits (azure auto-cancel is not working at the moment). Shouldn't make a difference to you, as I guess you just care about the last version, but ping me if this causes you any trouble. |
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.
@h-vetinari this PR is again too much going on. pls do this in multiple steps.
Both this PR and #22225 have had persistent a For example in https://travis-ci.org/pandas-dev/pandas/jobs/453820311 or https://travis-ci.org/pandas-dev/pandas/jobs/453822449:
and
There's also a
I've narrowed the ResourceWarning down to the parquet-s3 tests, but couldn't figure out a way to fix it despite many tries, so I'm skipping them for now. |
b1dead0
to
accab28
Compare
Codecov Report
@@ Coverage Diff @@
## master #23192 +/- ##
==========================================
- Coverage 92.25% 92.25% -0.01%
==========================================
Files 161 161
Lines 51383 51410 +27
==========================================
+ Hits 47404 47428 +24
- Misses 3979 3982 +3
Continue to review full report at Codecov.
|
073a542
to
9183b50
Compare
conceptually this PR is good, but it does too much in a single go, diluting the intent. several much smaller scope PR's would be better. |
git diff upstream/master -u -- "*.py" | flake8 --diff
Since #22286 and #21855 have stalled completely, I've decided to go ahead with this independently.