8000 API: Series.str-accessor infers dtype (and Index.str does not raise on all-NA) by h-vetinari · Pull Request #23167 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

API: Series.str-accessor infers dtype (and Index.str does not raise on all-NA) #23167

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 26 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e377b69
API: Series.str-accessor infers dtype
h-vetinari Nov 29, 2018
88b7b53
Forbid encode on pure bytes as well
h-vetinari Nov 29, 2018
b19a40d
Remove merge artefact
h-vetinari Nov 30, 2018
fb7da6b
fix isort
h-vetinari Nov 30, 2018
f8ffb0d
merge in API: fix str-accessor on CategoricalIndex
h-vetinari Dec 2, 2018
4404d4f
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Dec 2, 2018
4aedad4
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Dec 2, 2018
1285fd5
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Dec 3, 2018
332d14b
Review (jreback)
h-vetinari Dec 3, 2018
8716394
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Dec 19, 2018
44a9146
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Mar 4, 2019
e34097f
Add method name for casefold
h-vetinari Mar 4, 2019
25a046c
Adapt error msg
h-vetinari Mar 4, 2019
9307ba1
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Mar 8, 2019
c9c7496
Review (jreback)
h-vetinari Mar 8, 2019
0e0f6b0
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari Mar 27, 2019
bf4d7cf
Review (jreback)
h-vetinari Mar 27, 2019
a68ea5f
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari May 13, 2019
5ae1533
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari May 14, 2019
b8f6792
Merge remote-tracking branch 'upstream/master' into str_infer
h-vetinari May 30, 2019
0c7e233
fix merge artefact
h-vetinari May 30, 2019
1168ca2
Review (jreback)
h-vetinari May 30, 2019
ab980ec
commit whatsnew changes
h-vetinari May 30, 2019
a996889
retrigger azure
h-vetinari May 30, 2019
4adef35
remove mentions of 'unicode'
h-vetinari May 30, 2019
f62e344
improve docstring for ._validate
h-vetinari May 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review (jreback)
  • Loading branch information
h-vetinari committed Mar 8, 2019
commit c9c74966e90ce6745c3c9481163ed2404988629c
11 changes: 11 additions & 0 deletions doc/source/user_guide/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ and replacing any remaining white spaces with underscores:
``.str`` methods which operate on elements of type ``list`` are not available on such a
``Series``.

.. _text.warn_types:

.. warning::

Before v.0.25.0, the ``.str``-accessor did only the most rudimentary type checks. Starting with
v.0.25.0, the type of the Series is inferred (like it has already been the case for ``Index.str``),
Copy link
Contributor

Choose a reason for hiding this comment

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

remove what you have in the parens (like it...)

and the allowed types (i.e. strings) are enforced more rigorously.

Generally speaking, the ``.str`` accessor is intended to work only on strings. With very few
exceptions, other uses are not supported, and may be disabled at a later point.


Splitting and Replacing Strings
-------------------------------
Expand Down
9 changes: 9 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ Conversion
Strings
^^^^^^^

**The ``.str``-accessor performs stricter type checks**

Copy link
Contributor

Choose a reason for hiding this comment

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

make a new subsection instead, and show an example of previous and current behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Currently I can only show that things now raise an error that did not before (e.g. trying .str on bytes). This will then have to be updated once we have a .bytes accessor.

Due to the lack of a native string dtype in numpy, :attr:`Series.str` only checked whether the data was of ``object`` dtype.
From now on, the inferred dtype of the Series is checked to be correct (particularly, not ``'bytes'``), as :attr:`Index.str` does already.

For more details, see this :ref:`warning<text.warn_types>`.

**Other bugs**

- Bug in the ``__name__`` attribute of several methods of :class:`Series.str`, which were set incorrectly (:issue:`23551`)
-
-
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ def forbid_nonstring_types(forbidden, name=None):

Parameters
----------
forbidden : list or None
forbidden : list-of-str or None
List of forbidden non-string types, may be one or more of
`['bytes', 'mixed', 'mixed-integer']`.
name : str, default None
Expand Down
0