-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
ENH: Make Series.update() use objects coercible to Series #33502
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
7c144b6
to
18c3cef
Compare
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -98,6 +98,8 @@ Other enhancements | |||
This can be used to set a custom compression level, e.g., | |||
``df.to_csv(path, compression={'method': 'gzip', 'compresslevel': 1}`` | |||
(:issue:`33196`) | |||
- :meth:`Series.update` now accepts objects that can be coerced to a Series, | |||
such as `dict` and `list`, mirroring the behavior of `DataFrame.update` (:issue:`33215`) |
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.
You can use :class:`Series`, :meth:`DataFrame.update` and double back ticks around the other keywords for better rendering
|
||
expected = Series([1, 5, 1, 4]) | ||
|
||
tm.assert_series_equal(s, 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.
Do you think you could remove the excess white space and parametrize over the cases tested 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.
Done!
pandas/core/series.py
Outdated
@@ -2764,7 +2764,7 @@ def combine_first(self, other) -> "Series": | |||
|
|||
Parameters | |||
---------- | |||
other : Series | |||
other : Series, or object coercible into Series |
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.
It looks like you're editing the docstring of combine_first, can you modify the one for update instead? @WillAyd do you think it'd be good to add an example to the docstring for this behavior?
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.
comments, looks good. ping when updated & green
], | ||
) | ||
def test_update_from_non_series(self, s, d, expected): | ||
s.update(d) |
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 add the issue number here as a comment
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.
Done
(Series([1, 2, 3, 4]), [np.nan, 5, 1], Series([1, 5, 1, 4])), | ||
], | ||
) | ||
def test_update_from_non_series(self, s, d, 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.
can you rename: s-> series, d-> other
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.
Done
thanks @dericke |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Allows
Series.update()
to accept objects that can be coerced into aSeries
, like adict
. This mirrors the existing behavior ofDataFrame.update()
.