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

changes to add root_notation flag in mathml.py. #15901

Merged
merged 10 commits into from Feb 7, 2019
Merged

changes to add root_notation flag in mathml.py. #15901

merged 10 commits into from Feb 7, 2019

Conversation

shiksha11
Copy link
Contributor

@shiksha11 shiksha11 commented Feb 2, 2019

Made Changes to fix issue #14033.
Added root_noatation flag in mathml.py.

>>>print_mathml(x**(S(1)/3), printer = 'presentation')
<mroot>
	<mi>x</mi>
	<mn>3</mn>
</mroot>

>>>print_mathml(x**(S(1)/3), printer = 'presentation', root_notation=False)
<msup>
	<mi>x</mi>
	<mfrac>
		<mn>1</mn>
		<mn>3</mn>
	</mfrac>
</msup>
  • printing
    • Added the flag root_notation to the MathML printerchanges made in mathml.py. If set to False, exponents of the form 1/n are printed in fractional form. It is set as True (default), the exponents are printed in root form.

@sympy-bot
Copy link

sympy-bot commented Feb 2, 2019

Hi, I am the SymPy bot (v136). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • printing
    • Added the flag root_notation to the MathML printerchanges made in mathml.py. If set to False, exponents of the form 1/n are printed in fractional form. It is set as True (default), the exponents are printed in root form. (#15901 by @oscargus and @shiksha11)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.4.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

Made Changes to fix issue #14033.
Added root_noatation flag in mathml.py.

```javascript
>>>print_mathml(x**(S(1)/3), printer = 'presentation')
<mroot>
	<mi>x</mi>
	<mn>3</mn>
</mroot>

>>>print_mathml(x**(S(1)/3), printer = 'presentation', root_notation=False)
<msup>
	<mi>x</mi>
	<mfrac>
		<mn>1</mn>
		<mn>3</mn>
	</mfrac>
</msup>
```


<!-- BEGIN RELEASE NOTES -->
* printing
    * Added the flag root_notation to the MathML printerchanges made in mathml.py.  If set to False, exponents of the form 1/n are printed in fractional form. It is set as True (default), the exponents are printed in root form.

<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@shiksha11 shiksha11 changed the title changes to add root_notation flag in math.py. changes to add root_notation flag in mathml.py. Feb 2, 2019
@oscargus
Copy link
Contributor

oscargus commented Feb 3, 2019

Thanks!

The printing part looks good, but I do not think the logic with the settings are working. (Maybe you were waiting for the init task to be solved?)

I have now merged #15906 which has a working init. If you merge this (will probably be easier if you remove both your init methods before merging master) you should be able to execute your code. Also, you can remove your default_setting.

Once that is done, please add a few tests to show that the flag changes the behavior. (Maybe it doesn't work in the content printer. Probably the settings handling should have been put there, but I was a bit too quick to merge #15906 I realize, as I didn't want to stall this PR.)

@@ -905,7 +920,7 @@ def mathml(expr, printer='content', **settings):
return MathMLContentPrinter(settings).doprint(expr)


def print_mathml(expr, printer='content', **settings):
def print_mathml(expr, printer='content', symbol_names=None, root_notation=True, order=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be very useful if you can add all the settings from #15877 here. Starting with printer and order (to not break backwards compatibility) and then the rest in alphabetical order.

Even better if they are also added below, but here is the first priority.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, i am adding those settings.

@@ -112,6 +115,12 @@ class MathMLContentPrinter(MathMLPrinterBase):
"""
printmethod = "_mathml_content"

def __init__(self, settings=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this and rely on the parent class instead I think.

@@ -466,6 +475,12 @@ class MathMLPresentationPrinter(MathMLPrinterBase):
"""
printmethod = "_mathml_presentation"

def __init__(self, settings=None):
Printer.__init__(self, settings)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, it is better to call MathMLPrinterBase instead. However, this is just for future reference as this is already done in #15906. (Even better is super(MathMLPresentationPrinter, self).__init__(self, settings).)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

@shiksha11
Copy link
Contributor Author

Thanks!

The printing part looks good, but I do not think the logic with the settings are working. (Maybe you were waiting for the init task to be solved?)

I have now merged #15906 which has a working init. If you merge this (will probably be easier if you remove both your init methods before merging master) you should be able to execute your code. Also, you can remove your default_setting.

Once that is done, please add a few tests to show that the flag changes the behavior. (Maybe it doesn't work in the content printer. Probably the settings handling should have been put there, but I was a bit too quick to merge #15906 I realize, as I didn't want to stall this PR.)

The changes i made work for content printer as well.

@oscargus
Copy link
Contributor

oscargus commented Feb 3, 2019

Ah, so _settings is set in Printer.__init__? OK, then it should just be to resolve the conflicts and add a test and it should be good to go!

@shiksha11
Copy link
Contributor Author

Ah, so _settings is set in Printer.__init__? OK, then it should just be to resolve the conflicts and add a test and it should be good to go!

I have added root_notation in _default_settings of MathMLPrinterBase. Now, should i make the changes so that this flag works for both presentation or content printing or just presentation?

@Abdullahjavednesar
Copy link
Member

@shiksha11 make sure you resolve the conflicting file and add a test to support the changes you've made before you proceed ahead.
@oscargus thanks for the review 🙂

@@ -466,7 +467,7 @@ class MathMLPresentationPrinter(MathMLPrinterBase):

def __init__(self, settings=None):
MathMLPrinterBase.__init__(self, settings)

Copy link
Contributor

Choose a reason for hiding this comment

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

Here are some spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed those spaces.
Are there any tests which i can run locally to check for these errors related to spaces or code style?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, python bin\test quality on "Windows", bin/test quality on "Linux". (Citation marks as exact usage will vary depending on so many things...)

Takes less than a minute so clearly worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, thanks :)

Copy link
Contributor

Choose a reason for hiding this comment

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

It is also possible to run a subset of the tests by replacing quality with the module name, in this case printing. One can also run only a specific test with the -k flag, in your case -k test_presentation_printmethod (using printingas well will probably speed things up as not all tests are searched).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem now is that the flag is passed when instantiating the printer, not in the doprint method. So you will need to instantiate a new printer with the flag. Probably makes sense to move it to a separate test as well to make it clear that it uses a different printer instantiation.

Yes, i was initially unsure about adding the test in the doprint method.

@oscargus
Copy link
Contributor

oscargus commented Feb 5, 2019

I added the missing import. If the tests pass it should be good to go. Thanks!

@oscargus
Copy link
Contributor

oscargus commented Feb 6, 2019

The problem now is that the flag is passed when instantiating the printer, not in the doprint method. So you will need to instantiate a new printer with the flag. Probably makes sense to move it to a separate test as well to make it clear that it uses a different printer instantiation.

@oscargus
Copy link
Contributor

oscargus commented Feb 6, 2019

I added that now.

Primarily to get a new Azure run, which seems to have not started last time.
@shiksha11
Copy link
Contributor Author

I added that now.

Thanks!!

@shiksha11
Copy link
Contributor Author

shiksha11 commented Feb 6, 2019

The problem now is that the flag is passed when instantiating the printer, not in the doprint method. So you will need to instantiate a new printer with the flag. Probably makes sense to move it to a separate test as well to make it clear that it uses a different printer instantiation.

Did you understand the problem from the error messages ?

@oscargus
Copy link
Contributor

oscargus commented Feb 6, 2019

Yes.

From https://travis-ci.org/sympy/sympy/jobs/488910309

______ sympy/printing/tests/test_mathml.py:test_presentation_printmethod _______
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/utilities/runtests.py", line 1306, in _timeout
    function()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/printing/tests/test_mathml.py", line 464, in test_presentation_printmethod
    assert mpp.doprint(x**(S(1)/3)) == '<mroot><mi>x</mi><mn>3</mn></mroot>'
NameError: name 'S' is not defined

and later from https://travis-ci.org/sympy/sympy/jobs/489118673

______ sympy/printing/tests/test_mathml.py:test_presentation_printmethod _______
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/utilities/runtests.py", line 1306, in _timeout
    function()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/printing/tests/test_mathml.py", line 465, in test_presentation_printmethod
    assert mpp.doprint(x**(S(1)/3), root_notation=False) == '<msup><mi>x</mi><mfrac><mn>1</mn><mn>3</mn></mfrac></msup>'
TypeError: doprint() got an unexpected keyword argument 'root_notation'

Not sure why the Azure tests are not running though...

@shiksha11
Copy link
Contributor Author

Yes.

From https://travis-ci.org/sympy/sympy/jobs/488910309

______ sympy/printing/tests/test_mathml.py:test_presentation_printmethod _______
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/utilities/runtests.py", line 1306, in _timeout
    function()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/printing/tests/test_mathml.py", line 464, in test_presentation_printmethod
    assert mpp.doprint(x**(S(1)/3)) == '<mroot><mi>x</mi><mn>3</mn></mroot>'
NameError: name 'S' is not defined

and later from https://travis-ci.org/sympy/sympy/jobs/489118673

______ sympy/printing/tests/test_mathml.py:test_presentation_printmethod _______
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/utilities/runtests.py", line 1306, in _timeout
    function()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/sympy-1.4.dev0-py3.6.egg/sympy/printing/tests/test_mathml.py", line 465, in test_presentation_printmethod
    assert mpp.doprint(x**(S(1)/3), root_notation=False) == '<msup><mi>x</mi><mfrac><mn>1</mn><mn>3</mn></mfrac></msup>'
TypeError: doprint() got an unexpected keyword argument 'root_notation'

Not sure why the Azure tests are not running though...

Thanks! Now i understand how to interpret those messages.

@oscargus oscargus merged commit d05637a into sympy:master Feb 7, 2019
@oscargus
Copy link
Contributor

oscargus commented Feb 7, 2019

I merge it now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants