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

Checked if subs argument was zip object and added test #19159

Merged
merged 8 commits into from Sep 5, 2020

Conversation

gfolbe318
Copy link
Contributor

@gfolbe318 gfolbe318 commented Apr 21, 2020

  • matrices
    • changed subs function to check if input is zip
    • added tests in test_commonmatrix.py

@sympy-bot
Copy link

sympy-bot commented Apr 21, 2020

Hi, I am the SymPy bot (v160). 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:

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

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.

<!-- BEGIN RELEASE NOTES -->

* matrices
    * changed subs function to check if input is zip
    * added tests in test_commonmatrix.py

<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov
Copy link

codecov bot commented Apr 21, 2020

Codecov Report

Merging #19159 into master will increase coverage by 0.000%.
The diff coverage is 100.000%.

@@            Coverage Diff            @@
##            master    #19159   +/-   ##
=========================================
  Coverage   75.849%   75.849%           
=========================================
  Files          670       670           
  Lines       173699    173701    +2     
  Branches     40978     40979    +1     
=========================================
+ Hits        131750    131752    +2     
- Misses       36209     36213    +4     
+ Partials      5740      5736    -4     

@smitgajjar
Copy link
Contributor

Please refer this and other PR comments for writing proper PR template. Also, add a short description about what you changed and what gets fixed.

@@ -2118,6 +2118,10 @@ def subs(self, *args, **kwargs): # should mirror core.basic.subs
>>> Matrix(_).subs(y, x)
Matrix([[x]])
"""

if isinstance(args[0], zip):
args = (list(args[0]),)
Copy link
Contributor

Choose a reason for hiding this comment

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

There are other possibilities for what args[0] could be that would have this problem e.g. map etc (athough zip is most common).

I think it would be better to do something like convert args to a tuple if whenever it is not a tuple.

Also this would ignore args[1] etc if supplied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @oscarbenjamin, thanks for the feedback. In all honesty, I didn't realize that creating a fork of the repository would still notify contributors of any pull requests I made...rookie mistake! I tried inputs on maps and those seemed to work. I'll now try to enhance this pull request like you suggested and also add test cases as well as some release notes.

Copy link
Contributor Author

@gfolbe318 gfolbe318 Apr 21, 2020

Choose a reason for hiding this comment

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

Also, would you recommend that I create a completely new PR? Or can I just modify this one?

Copy link
Member

Choose a reason for hiding this comment

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

Or can I just modify this one?

Modifying this one should do.

@gfolbe318
Copy link
Contributor Author

@smitgajjar I will add release notes, but I also have to modify some other files and write test cases. Should I close this PR and make another? Sorry, I am new to this.

@smitgajjar
Copy link
Contributor

You can continue making commits on this branch (i.e. updating other files or adding tests). No need to make a new PR.

@smitgajjar
Copy link
Contributor

smitgajjar commented Apr 21, 2020

Refer the Sympy's development workflow, especially patch updates here :)

@gfolbe318 gfolbe318 changed the title made fix to matrix subs function Checked if subs argument was zip object and added tests Apr 22, 2020
@gfolbe318 gfolbe318 changed the title Checked if subs argument was zip object and added tests Checked if subs argument was zip object and added test Apr 22, 2020
@sympy-bot
Copy link

sympy-bot commented Apr 22, 2020

🟠

Hi, I am the SymPy bot (v160). I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it.

This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75.

The following commits add new files:

  • 5b643ae:
    • sympy/matrices/tests/test_commonmatrix.py.23eb1923b522b32a721d23f26c57bc56.py

The following commits delete files:

  • d9a820f:
    • sympy/matrices/tests/test_commonmatrix.py.23eb1923b522b32a721d23f26c57bc56.py

If these files were added/deleted on purpose, you can ignore this message.

@gfolbe318
Copy link
Contributor Author

gfolbe318 commented Apr 22, 2020

I did some thought about this error and came to the conclusion that this issue might be a little more difficult than I previously expected. Here is why:

The change proposed in #19159 (comment) will not work because (from my understanding), all input types that are not iterators work perfectly. Simply casting the argument to a tuple (if it is not so already) will cause inputs that are dictionaries and sets to fail and will result in a lot of code duplication from sympy/core/basic.py. It is also worth noting that when len(args) == 2, iterators are not valid inputs to the subs function.

The original piece of code I added should fix the issue it is addressing, but I am open to keep working on it to make it more generalized. I can also try something like this:

if iterable(args[0]):
    if(isinstance(args[0], map):
         #convert args[0] to list using args[0].items
    elif isinstance(args[0], ????):
        #would this happen?
    else:
         #convert args[0] to list using casting

Essentially, how would I go about identifying that my data structure is iterable but is not a map or set without code duplication? (Sorry for the multiple edits)

@oscarbenjamin
Copy link
Contributor

One possibility would be to do something like:

if len(args) == 1 and  not isinstance(args[0], (dict, set)) and iterable(args[0]) and not is_sequence(args[0]):
       args = (list(args[0]),)

I'm wondering though whether it might be better to punt entirely on trying to reimplement and part of subs (which is already implemented for Basic) and do:

    def subs(self, *args, **kwargs):
        return self.as_immutable().subs(*args, **kwargs).as_mutable()

@czgdp1807
Copy link
Member

@gfolbe318 Would you like to complete this PR? Please resolve the conflicts. Thanks for your contributions. Please do not close this PR.

@gfolbe318
Copy link
Contributor Author

Hello, yes. I apologize for the gaps in communication. I will take a closer look at it !

@gfolbe318
Copy link
Contributor Author

Just got back to this, apologies again for the delays. Things have been pretty hectic. I think my most recent fix should be good. I tried both of @oscarbenjamin 's suggestions and ended up going with the first one, as the second caused a recursion error. Hopefully I merged everything in correctly. Another thing I am struggling with is getting the release notes check to pass. Please let me know if you see any glaring errors with what I wrote. I have read the guidelines multiple times and looked at other examples, so I am assuming that I'm missing something small.

@gfolbe318
Copy link
Contributor Author

The Travis CI build failed, but after doing some investigation I read that it could've been due to a failed HTTP connection. How could I go about rerunning the build without committing a change?

@czgdp1807
Copy link
Member

I have resolved the conflicts. @gfolbe318 Can you see if it is okay? @oscarbenjamin Is there anything more to be done to let it in master?

@oscarbenjamin
Copy link
Contributor

Yes, this is good. Thanks!

@oscarbenjamin oscarbenjamin merged commit 9b40b1e into sympy:master Sep 5, 2020
@gfolbe318
Copy link
Contributor Author

Thanks everyone!

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

6 participants