Skip to content

[RFC] Simple __repr__ with global flag #9039

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
wants to merge 13 commits into from

Conversation

amueller
Copy link
Member

@amueller amueller commented Jun 7, 2017

Following up on #7618 which attempted a fancy repr for Jupyter, this goes back to changing __repr__ in all cases to only show non-default parameters, configured by a global option.
The idea is to document the introduction of the argument, and I think set the configuration for the documentation, then change the default value in 2 versions. Docs a-coming.
ping @jnothman

@amueller amueller changed the title Simple repr Simple __repr__ with global flag Jun 7, 2017
@amueller amueller changed the title Simple __repr__ with global flag [WIP] Simple __repr__ with global flag Jun 7, 2017
@jnothman
Copy link
Member

jnothman commented Jun 7, 2017

How about we try merge #7548 and reuse its mechanics for global config...

@amueller
Copy link
Member Author

amueller commented Jun 7, 2017

@jnothman good point

@codecov
Copy link

codecov bot commented Jun 8, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@e31c4f1). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #9039   +/-   ##
=========================================
  Coverage          ?   96.19%           
=========================================
  Files             ?      331           
  Lines             ?    59667           
  Branches          ?        0           
=========================================
  Hits              ?    57395           
  Misses            ?     2272           
  Partials          ?        0
Impacted Files Coverage Δ
sklearn/model_selection/_search.py 98.3% <100%> (ø)

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 e31c4f1...6350191. Read the comment docs.

@amueller amueller changed the title [WIP] Simple __repr__ with global flag [MRG] Simple __repr__ with global flag Jun 8, 2017
@GaelVaroquaux
Copy link
Member

To summarize an discussion that I had IRL with @amueller: sometimes hiding the default is a dangerous thing, as the default is not good (for instance because it is impossible to have a uniformly good default). One example is n_clusters, or n_components. Another is n_estimators in RandomForests, which is at 10 right now (and that's way too low).

One suggestion is to add to the mechanism in this PR an estimator-specific whitelist of parameters that should always be listed.

@amueller
Copy link
Member Author

amueller commented Jun 8, 2017

hm I'm not as enthusiastic any more and I think maybe I don't want to make this a priority for the sprint, given all the other cool stuff we need to work on.

@amueller
Copy link
Member Author

amueller commented Jun 8, 2017

At least I fixed the pretty printing... comparison of pretty printing, pretty printing only changed parameters, pretty printing and coloring changed parameters, and the current repr.
image

@amueller
Copy link
Member Author

amueller commented Jun 8, 2017

the current pretty printing can't really work because it hands control to repr, and so as soon as you are in a list or dict, you can't control what's happening any more.

@amueller
Copy link
Member Author

amueller commented Jun 8, 2017

oh wait above was the simple example, here pretty print, pretty print with changed vs current:
image

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

This comment was pending. I'll try look later

filtered_params[k] = v
return filtered_params
return params

def __repr__(self):
Copy link
Member

Choose a reason for hiding this comment

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

I think there may be contexts in which we want to override the global option, such as in naming estimators in check_estimator tests..?

@jnothman
Copy link
Member

jnothman commented Jun 9, 2017 via email

@amueller
Copy link
Member Author

amueller commented Jun 9, 2017

Oh sorry, above comparison was not against master, it was against my hacked master. Here's what it actually looks like:

image

Marking changed parameters with color kinda failed. For pipeline, do you mark the whole estimator? Or just the estimator name? Or the parameter name (see example above).

@amueller
Copy link
Member Author

amueller commented Jun 9, 2017

The current ```repr`` makes no sense at all. There's an easy fix to the more consistent indentation and there's a larger fix (that I implemented) to actually pretty print by taking charge of dictionary, list and array formatting.

@amueller amueller changed the title [MRG] Simple __repr__ with global flag [RFC] Simple __repr__ with global flag Jun 9, 2017
@jnothman
Copy link
Member

jnothman commented Jun 10, 2017 via email

@amueller
Copy link
Member Author

@jnothman what do you think about the formatting vs the current formatting? @GaelVaroquaux liked it, might open a PR.

@jnothman
Copy link
Member

jnothman commented Jun 10, 2017 via email

@jnothman
Copy link
Member

A note: I believe that there are contexts in which the default parameters should not be shown, such as when printing out parameters (some of which are estimators) being searched.

@amueller
Copy link
Member Author

replaced by #11705

@amueller amueller closed this Dec 14, 2018
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.

3 participants