-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
[WIP] PR: Add SymPy support #129
base: master
Are you sure you want to change the base?
Conversation
Thaks for working on this @oscargus. However I think it is difficult to have this as it is taking too much space. We could add this maybe as a tooltip, but adding the whole pretty printed for sympy seems like too much. Thoughts @spyder-ide/core-developers ? |
I think it's too large as well. I don't think that it should be larger an one line. I like the tool tip though. We could even put the head(first ten lines) of a dataframe or a 2darray in a tool tip |
Precisely the point... these are small "toy" examples. Real examples would be even larger. I am 👎 on this change. |
That is why it truncates at (currently) 80 x 10. Still, I'd claim that it is useful to see simpler expression as this. But probably it is better to make a guess which representation is the best. Truncating a few lines may not be a problem, but if 100 lines are truncated, it is probably better to show it in a different format. |
Btw, why is there a "Resize row to contents" if things should be single line? |
Does this pretty print the whole SymPy expression and then truncate it? That could take a long time with large expressions, probably so long that in many cases it becomes annoying. As for the size, I don't think it needs to be one line, but ten lines seems too much. Perhaps details need to be discussed in an issue instead of this PR. My initial feeling is that anything pretty is hard to do, so maybe stick with the repr (provided performance is not an issue). |
I totally agree with this. What we could is that by doing double-click in a Sympy object, we show its text representation in our text editor. That way performance won't be an issue. |
Correct. Clearly,
This is easily adaptable. However, I do not believe that multi-line is of much benefit when doing repr. How should NumPy be treated? Currently, as shown, it plots up to 10 lines. The benefit of a PR is that one can actually try it out. |
That happens right now, the SymPy objects are fully editable (except that there is some incorrect printing in SymPy for a few functions, but that is worked on). I also have a Spyder branch where one can display the pretty representation of the expression in the object explorer (with warnings that it may take a long time etc). Ideally, one can also add LaTeX rendering there (or as a right-click in the variable explorer), possibly with a windowed viewer for large expressions. |
We definitely need to do something like that before merging this (i.e. to optimize as much as possible the display of Sympy objects). The problem is that
Where is that worked on? On Sympy or in Spyder?
That's very interesting! I'd really like to have that in Spyder!!
I agree with this too. It'd be a terrific addition! All in all I have to say I find this contribution very interesting because it could have a lot of value for heavy Sympy users. Pinging @asmeurer (Sympy maintainer) to know his opinion about this. |
It probably wouldn't be hard to write a "truncating" printer (or add support to the printers in SymPy), that stops printing after a certain number of characters. Also I'm not sure if printing is currently cached in SymPy, but that would definitely help for this use-case. |
if isinstance(value, (Integer, Float, Symbol, | ||
MatrixSymbol)): | ||
from sympy import pretty | ||
display = pretty(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to set num_columns
here to MAX_LINE_LENGTH
.
Thanks @asmeurer! Both suggestions are really good. @oscargus, could you take care of implementing them on Sympy? |
I plan to add better SymPy support to Spyder. What I want to obtain is that SymPy expressions are "supported" and shown in the Variable explorer, ideally using SymPy pretty printing, e.g.
As far as I can tell the only way to do this is to add support for it in spyder-kernels as these expressions will not be returned among the supported variables otherwise. Is this correct? Or is there a way to tell spyder-kernels to include even more types? Is this a good idea?
Furthermore, I do not really see a way to edit these expressions at the moment, I am more interested in them showing up in the Variable explorer. Hence, should I add a new type, displayable(?) here in addition to editable and picklable or should I just ignore editing attempts in Spyder?
As part of this, I am also planning to update the string truncation mechanism. Right now, a 3 x 3 matrix with zeros will print on three rows, but only as the total string length is below 70 characters. I plan to change that to that each row is evaluated and truncated at 70 characters, and rows above a certain threshold (10?) will be truncated in a sensible way. Hence, the introduction of the
truncated
flag with the purpose to say that the result is already truncated (for nparrays and SymPy expressions at least, more can be added).However, I have some problems testing spyder with my edited spyder-kernel. Any hints on how to obtain this? The problem seems to come from that pip(?) seems to think that I have Spyder 3.3.3 installed and therefore do not want to install a version > 1 using
pip install -e .
. (I do have 3.3.3 installed, but I want to run 4 from source...)(I also have some Spyder PRs upcoming with e.g. the ability to show pretty printed expressions in the Object explorer, which may be another way to obtain it, but as the SymPy expressions does not show in the Variable explorer by default it seems like a better idea to get them there first...)