Skip to content

API: change default for sep in str.cat (in docstring) #23443

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 11 commits into from
Nov 6, 2018

Conversation

h-vetinari
Copy link
Contributor

In the course of #22725, @WillAyd mentioned (about the sep=None in Series.str.cat being immediately overwritten by sep = '' if sep is None else sep):

Not anything you need to change in this PR but if we just overwrite None here it would probably make more sense to change the default function signature to simply be ''

This changes the default accordingly. Not sure this even needs a deprecation cycle? It's a pretty trivial change, and I doubt there are people relying on sep=None explicitly.

@pep8speaks
Copy link

Hello @h-vetinari! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Nov 1, 2018

Codecov Report

Merging #23443 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #23443   +/-   ##
=======================================
  Coverage   92.23%   92.23%           
=======================================
  Files         161      161           
  Lines       51197    51197           
=======================================
  Hits        47220    47220           
  Misses       3977     3977
Flag Coverage Δ
#multiple 90.61% <ø> (ø) ⬆️
#single 42.27% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/strings.py 98.58% <ø> (ø) ⬆️
pandas/core/indexes/datetimes.py 96.41% <0%> (ø) ⬆️
pandas/core/indexes/api.py 99% <0%> (ø) ⬆️
pandas/core/frame.py 97.03% <0%> (ø) ⬆️
pandas/core/generic.py 96.81% <0%> (ø) ⬆️
pandas/core/arrays/datetimes.py 98.84% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d78bd7a...2d1bf05. Read the comment docs.

@gfyoung gfyoung added API Design Strings String extension data type and string data labels Nov 1, 2018
@gfyoung
Copy link
Member

gfyoung commented Nov 1, 2018

Given that we were setting sep to the empty string under-hood, surfacing it explicitly as the default seems reasonable and wouldn't require a deprecation cycle.

@gfyoung gfyoung requested review from jreback and WillAyd and removed request for jreback November 1, 2018 17:58
@@ -2074,8 +2074,9 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):

If others is None, the method returns the concatenation of all
strings in the calling Series/Index.
sep : string or None, default None
If None, concatenates without any separator.
sep : string, default ''
Copy link
Member

Choose a reason for hiding this comment

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

string --> str; iirc when specifying parameter types we want to use the Python function name (e.g. bool instead of boolean, dict instead of dictionary, etc.). Can you also modify na_rep a couple lines below?

@@ -2196,8 +2197,6 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):

if isinstance(others, compat.string_types):
raise ValueError("Did you mean to supply a `sep` keyword?")
if sep is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think just adding the doc-string update is enough. we commondly accept none, then actuall do this check here. The reason is if you actually pass None your change will fail (pls add a test to check that)

@h-vetinari
Copy link
Contributor Author

@jreback

I think just adding the doc-string update is enough. we commondly accept none, then actuall do this check here. The reason is if you actually pass None your change will fail (pls add a test to check that)

How about the following - I went with re-adding the sep is None check, but emitting a warning. That will definitely not break anything, and emission of the warning should be very rare (as I believe hardly anyone will be passing sep=None directly).

@@ -2197,6 +2198,10 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
if isinstance(others, compat.string_types):
raise ValueError("Did you mean to supply a `sep` keyword?")
if sep is None:
warnings.warn('Passing `sep=None` to .str.cat is deprecated and '
Copy link
Contributor

Choose a reason for hiding this comment

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

pls remove this and just update as I suggested.

@@ -2051,7 +2051,7 @@ def _get_series_list(self, others, ignore_index=False):
return ([Series(others, index=idx)], False)
raise TypeError(err_msg)

def cat(self, others=None, sep=None, na_rep=None, join=None):
def cat(self, others=None, sep='', na_rep=None, join=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

there is likely some other check for sep is None in the codebase, this shouldn't pass, and as I said pls change back to the original modulo the doc-string.

@h-vetinari h-vetinari changed the title API: change default for sep in str.cat API: change default for sep in str.cat (in docstring) Nov 5, 2018
@h-vetinari
Copy link
Contributor Author

@jreback

there is likely some other check for sep is None in the codebase, this shouldn't pass, and as I said pls change back to the original modulo the doc-string.

What check for sep is None do you imagine there would be? It's not in the code of str.cat itself, but I guess I don't understand what you mean.

@jreback jreback added this to the 0.24.0 milestone Nov 6, 2018
@jreback jreback merged commit c6366f5 into pandas-dev:master Nov 6, 2018
@jreback
Copy link
Contributor

jreback commented Nov 6, 2018

thanks!

@h-vetinari h-vetinari deleted the str_cat_sep branch November 6, 2018 10:13
JustinZhengBC pushed a commit to JustinZhengBC/pandas that referenced this pull request Nov 14, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants