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

bug fixes and jupyter notebook support added #212

Merged
merged 3 commits into from
Apr 15, 2022

Conversation

cgnorthcutt
Copy link
Member

This PR adds three things to dataset.health_summary

  • Support for displaying pandas dataframe in a jupyter notebook instead of printing it out, but if the user runs health_summary in a terminal with no jupyter notebook, it should still print to console.
  • Fixed a bug that would cause health_summary to fail if pred_probs is not provided.
  • Fixed the printing of the header at the top.

@cgnorthcutt
Copy link
Member Author

Output of dataset.health_summary now looks like this if run in a jupyter notebook.

image

@codecov
Copy link

codecov bot commented Apr 15, 2022

Codecov Report

Merging #212 (7326108) into master (72a62ed) will decrease coverage by 0.29%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #212      +/-   ##
==========================================
- Coverage   95.48%   95.19%   -0.30%     
==========================================
  Files          12       12              
  Lines         909      915       +6     
  Branches      180      184       +4     
==========================================
+ Hits          868      871       +3     
- Misses         15       18       +3     
  Partials       26       26              
Impacted Files Coverage Δ
cleanlab/internal/util.py 99.01% <ø> (ø)
cleanlab/dataset.py 89.18% <100.00%> (-0.52%) ⬇️
cleanlab/filter.py 92.30% <0.00%> (-1.29%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72a62ed...7326108. Read the comment docs.

Comment on lines 462 to 468
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
display(df) # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
print(df) # terminal, not notebook
else:
print(df) # something else, but not notebook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative could be: just display(df) in L460 and delete these extra checks. They anyway just goto L470, which would happen anyway if try clause fails.

I ask because not sure if ZMQInteractiveShell is overly limiting. Maybe display(df) works in other envs as well?

Should keep as is if there's some specific situation where display(df) will not cause try to fail, but is not desirable to execute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI from my terminal console (shell = TerminalInteractiveShell), both display(df) and print(df) work fine. They just give same output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eg. in colab, I don't think shell == "ZMQInteractiveShell" but display(df) still would be preferred over print(df)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but similarly do not know the answer to your last question. I can make this change, but it makes exception handling more challenging for developers in the future if we wish to expand this functionality.

EDIT: i see for some terminals that have jupyter, get_ipython().__class__.__name__ returns Shell, so will change to try: display(df)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to your second and third comment, we still need error checking because in my console, i don't have IPython installed so it throws an error if i try to display

Copy link
Member

@jwmueller jwmueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just suggested possible minor improvement of the display(df) part

@cgnorthcutt cgnorthcutt merged commit fac6c11 into cleanlab:master Apr 15, 2022
@cgnorthcutt cgnorthcutt deleted the smart_display branch April 15, 2022 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants