-
Notifications
You must be signed in to change notification settings - Fork 20
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
Adds __str__
which generates a text rendering
#262
Conversation
I think this should be included in 0.6. It does not add a new interface that we have to define and we are free to change what |
I also took the liberty to use the same repr and str for the cpp skin and the main skin. |
I don't think we should expose things like:
In the regular Histogram. I'd rather wait and try to do this correctly. It would be a fine feature for 0.7.0. Also, an object's |
|
I'm not horribly against this if you really want it in, by the way. |
If |
I see no reason to delay this, as |
And I don't want |
It would feel weird for me for |
I am really open to change this, if this solution turns out to be bad, but I really think that fancy printing is better placed in an upper level library like hist. |
Having |
Things that produce strings should not check the terminal width. If you do: with open(output, 'w') as f:
print(histogram, file=f) that should not depend on your current terminal width!
That's why I'm okay with this if you want it in. I like not having the histogram printout in the C++ repr, since it is sometimes seen when you get an error, and having a huge repr is hard to manage. I do think it should be
I'd like it to rebin (eventually) for some really large number, like 1000, just so we don't kill terminals with printouts if someone tries to print it out (and could be a global configurable, like Numpy). This way it only affects users who would get a massive printout accidentally (and show would be fine not rebinning at all by default). Numpy used to do this a long time ago, and I had an 18,000,000 element array that used to kill it if accidentally displayed. |
Actually, something like the example above or: with open(output, 'w') as f:
f.write(histogram) Should not easily truncate/shink/rebin, so I think I just talked myself (or you did, not sure) out of str truncating. I still would be 100% okay with an emergency truncation roughly equivalent to Numpy's default (we could even use Numpy's setting as it's large at 1000, and |
The good thing about |
The original idea was to add
.show()
to generate the text rendering, with possibly some options on how to render. Then.__str__(self)
would call.show()
. However, this does not work well in the REPL, unless.show()
returns a special string class that has a modified__repr__(self)
:All that can be done, but I think this is overengineering. It is ok if the lowest layer just does something simple. I don't think we should even make it configurable. Upper layers will most likely override the display anyway with something custom.