Skip to content

Pandas inplace argument is not explicit True or False #14189

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
jrovegno opened this issue Sep 8, 2016 · 5 comments · Fixed by #14318
Closed

Pandas inplace argument is not explicit True or False #14189

jrovegno opened this issue Sep 8, 2016 · 5 comments · Fixed by #14318
Labels
API Design Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@jrovegno
Copy link

jrovegno commented Sep 8, 2016

Any Serie or DataFrame method with arguments inplace != [0, False, None, [], {}] process inplace operation.
Is not explicit True or False like in the documentation.
Other methods tested: where, mask, sort_index
Any bool(arg) == True is accepted
Like: inplace='Fail' , inplace=3, inplace=[0]

Maybe is not a bug, but can generate problems if someone is not careful using positional arguments, like me.

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
df.where(lambda x: x > 4, lambda x: x + 10, 'fail')

Expected Output

Out[72]: 
    A   B  C
0  11  14  7
1  12   5  8
2  13   6  9

output of pd.show_versions()

pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: AMD64 Family 18 Model 1 Stepping 0, AuthenticAMD
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 25.1.6
Cython: 0.23.4
numpy: 1.11.1
scipy: 0.18.0
statsmodels: 0.6.1
xarray: 0.8.1
IPython: 5.1.0
sphinx: 1.3.5
patsy: 0.4.1
dateutil: 2.5.1
pytz: 2016.2
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.1
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.6.0
bs4: 4.4.1
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.39.0
pandas_datareader: 0.2.0

@rforgione
Copy link
Contributor

Interesting -- I agree that this is a little misleading. Unless this is the expected/desired behavior or someone has worked on fixing it already, I'd love to see if I can help. I'm a new contributor and looking for something to get my feet wet with. Would love to get the input of someone with more experience before digging in. My initial thought was a common function enforce_bool_type that checks that the value is of type bool before returning, raising a TypeError otherwise, and changing if bool_value to if enforce_bool_type(bool_value) throughout the code base. Would love feedback!

@jreback
Copy link
Contributor

jreback commented Sep 9, 2016

sure this is possible, you can just do:

if not is_bool(inplace):
    raise ValueError(....nice error message...)

with some tests would be great

@jreback jreback added API Design Error Reporting Incorrect or improved errors from pandas Difficulty Novice labels Sep 9, 2016
@rforgione
Copy link
Contributor

great, thanks @jreback !

@jrovegno
Copy link
Author

jrovegno commented Sep 9, 2016

For example in where method here.
For me explicit would be: if inplace == True:
But I'm only a panda's user, i don't know nothing how it works.

@J535D165
Copy link
Contributor

The same holds for the copy argument. Also not explicit.

@rforgione rforgione mentioned this issue Sep 29, 2016
2 tasks
@jreback jreback added this to the Next Major Release milestone Sep 29, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants