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

confusing default behavior of print for bound method #23720

Closed
MLopez-Ibanez opened this issue Nov 15, 2018 · 4 comments
Closed

confusing default behavior of print for bound method #23720

MLopez-Ibanez opened this issue Nov 15, 2018 · 4 comments
Labels
Enhancement Output-Formatting __repr__ of pandas objects, to_string

Comments

@MLopez-Ibanez
Copy link

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd
x = pd.DataFrame([[0,1],[3,2]])
x.mean

Problem description

The above prints

<bound method DataFrame.mean of    0  1
0  0  1
1  3  2>

I don't see the point of printing the actual dataframe content. With large data frames, the output above is even more confusing. This is very confusing for beginners.

Expected Output

<bound method DataFrame.mean>

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-33-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.23.1
pytest: None
pip: 18.1
setuptools: 40.5.0
Cython: None
numpy: 1.14.5
scipy: 0.17.0
pyarrow: None
xarray: None
IPython: 7.1.1
sphinx: 1.3.6
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.3
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.1
html5lib: 0.999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@TomAugspurger
Copy link
Contributor

It doesn't seem like there's an easy way to change the repr of a bound method: https://stackoverflow.com/questions/21344862/can-i-change-a-python-bound-method-objects-str-attribute, or am I reading that wrong?

@MLopez-Ibanez
Copy link
Author

MLopez-Ibanez commented Nov 15, 2018

NumPy seems to work-around this issue somehow:

import numpy as np
a = np.array([1])
a.mean

prints

<function ndarray.mean>

and

a.__repr__

prints

<method-wrapper '__repr__' of numpy.ndarray object at 0x7fbac86b9670>

@gfyoung gfyoung added the Output-Formatting __repr__ of pandas objects, to_string label Nov 16, 2018
@TomAugspurger
Copy link
Contributor

Is that because ndarray is implemented in C?

@mroeschke
Copy link
Member

Thanks for the issue, but it appears this hasn't gotten traction in a while so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

4 participants