Skip to content
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

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

Merged
merged 26 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions doc/source/user_guide/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ and replacing any remaining whitespaces 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 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
40 changes: 38 additions & 2 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,43 @@ returned if all the columns were dummy encoded, and a :class:`DataFrame` otherwi
Providing any ``SparseSeries`` or ``SparseDataFrame`` to :func:`concat` will
cause a ``SparseSeries`` or ``SparseDataFrame`` to be returned, as before.

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

Due to the lack of more fine-grained dtypes, :attr:`Series.str` so far only checked whether the data was
of ``object`` dtype. :attr:`Series.str` will now infer the dtype data *within* the Series; in particular,
``'bytes'``-only data will raise an exception (except for :meth:`Series.str.decode`, :meth:`Series.str.get`,
:meth:`Series.str.len`, :meth:`Series.str.slice`), see :issue:`23163`, :issue:`23011`, :issue:`23551`.

*Previous Behaviour*:

.. code-block:: python

In [1]: s = pd.Series(np.array(['a', 'ba', 'cba'], 'S'), dtype=object)

In [2]: s
Out[2]:
0 b'a'
1 b'ba'
2 b'cba'
dtype: object

In [3]: s.str.startswith(b'a')
Out[3]:
0 True
1 False
2 False
dtype: bool

*New Behaviour*:

.. ipython:: python
:okexcept:

s = pd.Series(np.array(['a', 'ba', 'cba'], 'S'), dtype=object)
s
s.str.startswith(b'a')

.. _whatsnew_0250.api_breaking.incompatible_index_unions

Incompatible Index Type Unions
Expand Down Expand Up @@ -267,7 +304,6 @@ This change is backward compatible for direct usage of Pandas, but if you subcla
Pandas objects *and* give your subclasses specific ``__str__``/``__repr__`` methods,
you may have to adjust your ``__str__``/``__repr__`` methods (:issue:`26495`).


.. _whatsnew_0250.api_breaking.deps:

Increased minimum versions for dependencies
Expand Down Expand Up @@ -472,7 +508,7 @@ Conversion
Strings
^^^^^^^

-
- Bug in the ``__name__`` attribute of several methods of :class:`Series.str`, which were set incorrectly (:issue:`23551`)
-
-

Expand Down
Loading