Skip to content

Improvements to str_cat #12297

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

Closed
wants to merge 2 commits into from
Closed

Improvements to str_cat #12297

wants to merge 2 commits into from

Conversation

hack-c
Copy link

@hack-c hack-c commented Feb 11, 2016

closes #11435
closes #11334.

Modified behavior of str_cat to ignore NaN values in the Series by default.

Added some doc examples to make the behavior with nan more clear, and catch an error condition when a sep is passed instead of an others (array) as an argument and print a more intuitive error message.

This is a retry of PR #12000.

Before, if NaN values were present in the Series, calling cat() on it would return NaN, unlike the rest of the Series.str. API. This behavior has been amended to ignore NaN values by default.
(#11435)

A new, friendlier ValueError was also added to protect against the mistake of supplying the sep as an arg, rather than a kwarg.
(#11334)

    >>> Series(['a','b',np.nan,'c']).str.cat(sep=' ')
    'a b c'

    >>> Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?')
    'a b ? c'

    >>> Series(['a','b',np.nan,'c']).str.cat(' ')
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-3-338c379049e9> in <module>()
    ----> 1 Series(['a','b',np.nan,'c']).str.cat(' ')

    [...]

    ValueError: Did you mean to supply a `sep` keyword?

@jreback jreback added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Error Reporting Incorrect or improved errors from pandas Strings String extension data type and string data labels Feb 12, 2016
`sep` as an arg, rather than a kwarg.
(:issue:`11334`).

.. code-block:: python
Copy link
Contributor

Choose a reason for hiding this comment

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

make the first 2 an ipython block so they run, the 3rd can be a code-block (just so you can show the error and not the entire traceback)

@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

looks good.

some small comments and you have linting errors:

linting -> pandas/core
pandas/core/strings.py:4:80: E501 line too long (84 > 79 characters)
linting -> pandas/io
linting -> pandas/stats
linting -> pandas/compat
linting -> pandas/sparse
linting -> pandas/tools
linting -> pandas/tseries
linting -> pandas/tests
pandas/tests/test_strings.py:2463:24: E231 missing whitespace after ','
pandas/tests/test_strings.py:2463:28: E231 missing whitespace after ','
pandas/tests/test_strings.py:2463:32: E231 missing whitespace after ','
pandas/tests/test_strings.py:2471:5: E303 too many blank lines (2)
linting -> pandas/computation
linting -> pandas/util

@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

ping when green.

@jreback jreback added this to the 0.18.0 milestone Feb 12, 2016
@jreback jreback closed this in a11766f Feb 12, 2016
@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

@hack-c thanks, I make the flake fixes.

@hack-c
Copy link
Author

hack-c commented Feb 12, 2016

Hey @jreback so is this all done?

@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

yep all done. thanks!

just trying to get the 0.18.0RC1 out the door :)

@hack-c
Copy link
Author

hack-c commented Feb 12, 2016

Ok, great @jreback!

How can I help? I want to do more :)

@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

@hack-c great!

just troll issues, you can select the difficulty labels as you want!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Strings String extension data type and string data
Projects
None yet
2 participants