Skip to content

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

Merged
merged 13 commits into from
Apr 26, 2020

Conversation

dericke
Copy link
Contributor

@dericke dericke commented Apr 12, 2020

Allows Series.update() to accept objects that can be coerced into a Series, like a dict. This mirrors the existing behavior of DataFrame.update().

@dericke dericke changed the title Series update coercible ENH: Make Series.update() use objects coercible to Series Apr 12, 2020
@dericke dericke marked this pull request as ready for review April 12, 2020 19:59
@dericke dericke force-pushed the series-update-coercible branch from 7c144b6 to 18c3cef Compare April 16, 2020 01:43
@@ -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`)
Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -2764,7 +2764,7 @@ def combine_first(self, other) -> "Series":

Parameters
----------
other : Series
other : Series, or object coercible into Series
Copy link
Member

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?

@pep8speaks
Copy link

pep8speaks commented Apr 25, 2020

Hello @dericke! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-04-26 01:39:36 UTC

Copy link
Contributor

@jreback jreback left a 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)
Copy link
Contributor

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

Copy link
Contributor Author

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):
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jreback jreback added this to the 1.1 milestone Apr 25, 2020
@jreback jreback merged commit 4468823 into pandas-dev:master Apr 26, 2020
@jreback
Copy link
Contributor

jreback commented Apr 26, 2020

thanks @dericke

@dericke dericke deleted the series-update-coercible branch April 27, 2020 04:32
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PROPOSAL] Make Series.update() accept a dictionary
4 participants