-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
__str__ and __repr__ are ignored for custom iterable objects #17695
Comments
You might try looking in pandas/pandas/io/formats/format.py Line 1765 in f9d88cd
pandas/pandas/io/formats/format.py Line 1803 in f9d88cd
Presumably we cast to |
to be honest this is not real well supported, nor intended. you are pretty much on your own. putting anything else besides scalars inside a Series/DataFrame is non-idiomatic. There will be some support for containers or things (e.g. lists / arrays) in pandas2. |
I think if we can support formatting without too much effort then we should. @dmyersturnbull if you can track down the issue and suggest a fix, it'd probably be accepted. |
The reason is because in our 'pretty print' implementation, we have a special method for sequences that can follow the pandas/pandas/io/formats/printing.py Lines 97 to 126 in f9d88cd
Which more or less hardcodes the possible results (depending on whether setitem exists, it will look like list of tuple). I am not directly sure of a way to both follow the repr of custom objects and still be able to limit the number of items showed for normal reprs. |
I posted a comment on ipython/ipython#2379, but I realized this may be specific to Pandas. I'm using IPython 6.2.0, Python 3.5, Jupyter 4.3.0, and Pandas 0.20.1.
Pandas won't use
__str__
or__repr__
(or anything I can find) to display an iterable object that defines__len__
Code Sample, a copy-pastable example if possible
Problem description
I've implemented
__str__
and__repr__
on an iterable class with good reason, and it being iterable shouldn't override that behavior.Expected Output
I expected and want to see this printed both with and without
__len__
:Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: