-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
pretty.install() fix for some objects with _repr_*_
#1804
Conversation
For all of the mimetypes that Jupyter notebook can display, we check if the method exists and ensure it doesn't return None. If this is the case, we delegate rendering to the notebook. Otherwise, Rich will be used to render. https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display
LGTM - Could you add that to CHANGELOG.md |
👍 |
So cool, many thanks to you both. |
That's likely because pd.Series has support for advanced rendering in Jupyter. We don't want to use Rich's printing if the object already knows how to format itself. |
Fine with me, thanks anyway! |
Type of changes
Checklist
Description
The issue is that Rich assumes that if a
_repr_*_
method exists on an object, then notebook will definitely render that object.However, notebook only supports a subset of mimetypes, and even in the case of supported mimetypes, some libraries (e.g.
pandas
) support toggling off functionality, which results in the_repr_*_
for that mimetype returningNone
.For example,
pd.Series
has a_repr_latex_
method, but by default the config for it ("display.latex.repr"
) is switched off and sopd.Series._repr_latex_
returnsNone
.We need something a little finer-grained and more aware of the notebook capabilities.
For all of the mimetypes that Jupyter notebook can display, we check if the corresponding
_repr_*_
special method exists and ensure it doesn't returnNone
. If it returnsNone
, Rich will print it, otherwise the notebook will render it.