question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Unexpected keyword argument `maxsplit` on `rsplit` even though it is accepted in vanilla Python

See original GitHub issue

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> string = "foo,bar,lorep"
>>> string.rsplit(",", maxsplit=1)  # This works as expected
['foo,bar', 'lorep']
>>> pd.DataFrame({"a": [string]})["a"].str.rsplit(",", maxsplit=1)  # Use kwarg maxsplit
TypeError: rsplit() got an unexpected keyword argument 'maxsplit'
>>> pd.DataFrame({"a": [string]})["a"].str.rsplit(",", 1)  # Change kwarg to arg
0    [foo,bar, lorep]
Name: a, dtype: object

Issue Description

When using pd.Series.str.rsplit in Pandas, the accepted kwargs are inconsistent with Python’s.

Python’s str.rsplit accepts the kwarg maxsplit=, while Panda’s pd.Series.str.rsplit does not.

Expected Behavior

I expect Panda’s pd.Series.str.rsplit to behave identically to Python’s str.rsplit, this includes accepting the same kwargs, namely maxsplit= in this case.

Installed Versions

pd.show_versions()
/Users/pawlu/.virtualenvs/pandas-debug-kqdr/lib/python3.9/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS
------------------
commit           : 47494a48edf25d5a49b0fb5b896b454c15c83595
python           : 3.9.12.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 21.4.0
Version          : Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.5.0.dev0+978.g47494a48e
numpy            : 1.22.4
pytz             : 2022.1
dateutil         : 2.8.2
setuptools       : 62.2.0
pip              : 22.1.2
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : 8.4.0
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
zstandard        : None

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
MrShevancommented, Jun 20, 2022

Hi, Can I take on me? 😃

1reaction
MarcoGorellicommented, Jun 20, 2022

Yeah go ahead

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does str.split not take keyword arguments? - Stack Overflow
str.split is a builtin method implemented in C. Unfortunately some builtin functions/methods do not accept keyword arguments. See this bug report.
Read more >
Issue 14763: string.split maxsplit documented incorrectly
msg160273 ‑ (view) Author: Fj (Fj) Date: 2012‑05‑09 11:30 msg160278 ‑ (view) Author: Roundup Robot (python‑dev) Date: 2012‑05‑09 11:59 msg160279 ‑ (view) Author: Ezio Melotti...
Read more >
pandas.Series.str.split — pandas 0.23.3 documentation
Split string on a separator, returning the before, separator, and after components. Notes. The handling of the n keyword depends on the number...
Read more >
The Python Library Reference - Scientific computing wiki
describes the standard library that is distributed with Python. ... All non-keyword arguments are converted to strings like str() does and ...
Read more >
Python String split() Method - W3Schools
Parameter, Description. separator, Optional. Specifies the separator to use when splitting the string. By default any whitespace is a separator. maxsplit ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found