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

AttributeError raised by method __eq__ of poset element #12351

Closed
seblabbe opened this issue Jan 25, 2012 · 19 comments
Closed

AttributeError raised by method __eq__ of poset element #12351

seblabbe opened this issue Jan 25, 2012 · 19 comments

Comments

@seblabbe
Copy link
Contributor

Using sage-4.7.2

sage: P = Poset([[1,2],[4],[3],[4],[]])
sage: P(0) == int(0)
Traceback (most recent call last):
...
AttributeError: 'int' object has no attribute 'parent'

This error is raised when ploting a poset :

sage: m = WordMorphism('a->abb,b->ba')
sage: w = m.fixed_point('a')
sage: prefix = Word(list(w[:100]))
sage: pals = prefix.palindromes()
sage: poset = Poset((pals, lambda x,y: x.is_factor(y)))
sage: H = poset.hasse_diagram()
sage: H.plot()
Traceback (most recent call last):
...
AttributeError: 'int' object has no attribute 'parent'

CC: @sagetrac-sage-combinat

Component: combinatorics

Keywords: poset

Author: David Loeffler

Reviewer: Nicolas M. Thiéry, Simon King

Merged: sage-5.0.beta9

Issue created by migration from https://trac.sagemath.org/ticket/12351

@simon-king-jena
Copy link
Member

comment:1

The problem was in the comparison of poset elements. Comparing a poset element with any object that has no parent (for example, comparison with a Python int) resulted in an error.

I thought the straight forward way to fix it is: Use sage.structure.element.parent(bla) instead of bla.parent().

With the patch, plotting the Hasse diagram works, and the bug fix is doctested. Needs review, then!

@simon-king-jena
Copy link
Member

Author: Simon King

@seblabbe
Copy link
Contributor Author

comment:2

Great!

I tested it (on sage-4.7.2) and it solves the problem. All tests pass on sage/combinat repository. Documentation builds fine. Positive review.

But now, I get another problem. When the package sage -i dot2tex is installed the method layout_graphviz gets called by plot and it seems broken for another reason. But this should be another ticket :

sage: H.plot()
Traceback (most recent call last):
...
AttributeError: 'str' object has no attribute 'iteritems'

which is also obtained by doing

sage: H.layout_graphviz()    # require dot2tex
Traceback (most recent call last):
...
AttributeError: 'str' object has no attribute 'iteritems'

@seblabbe
Copy link
Contributor Author

Reviewer: Sébastien Labbé

@seblabbe
Copy link
Contributor Author

comment:3

But now, I get another problem.

This is now #12364.

@seblabbe
Copy link
Contributor Author

comment:4

Same lines are edited by #11559. One will have to adapt to the other one.

@seblabbe

This comment has been minimized.

@seblabbe
Copy link
Contributor Author

comment:5

Changed the ticket title and its description since the original problem (hasse diagram ploting) might be (is?) solved indirectly by #10998.

@seblabbe seblabbe changed the title AttributeError when ploting a poset AttributeError raised by method __eq__ of poset element Jan 26, 2012
@nthiery
Copy link
Contributor

nthiery commented Jan 26, 2012

comment:6

Replying to @seblabbe:

Changed the ticket title and its description since the original problem (hasse diagram ploting) might be (is?) solved indirectly by #10998.

I removed the positive review, just in case we decide that this should be resolved as a duplicate of #10998.

@simon-king-jena
Copy link
Member

comment:7

Replying to @nthiery:

Replying to @seblabbe:

Changed the ticket title and its description since the original problem (hasse diagram ploting) might be (is?) solved indirectly by #10998.

I removed the positive review, just in case we decide that this should be resolved as a duplicate of #10998.

Since #10998 does not touch the __eq__ method, I suggest that one first checks whether the bug triggered by comparing a poset element with a Python int is really fixed by #10998.

@simon-king-jena
Copy link
Member

comment:8

Sorry, I can't test whether #10998 fixes the bug in comparison: It is in conflict with #11900, which is merged into sage-5.0.beta0

@simon-king-jena
Copy link
Member

comment:9

I just tested that the error vanishes with #10998. From that point of view, one could suggest that the ticket be resolved as duplicate.

On the other hand, having parent(bla) instead of bla.parent() is another layer of security and won't hurt.

I leave the decision to you.

@nthiery
Copy link
Contributor

nthiery commented Mar 11, 2012

comment:10

Replying to @simon-king-jena:

I just tested that the error vanishes with #10998. From that point of view, one could suggest that the ticket be resolved as duplicate.

On the other hand, having parent(bla) instead of bla.parent() is another layer of security and won't hurt.

I leave the decision to you.

I don't mind. In case we go for it, we might as well use "sage.structure.sage_object.have_same_parent".

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 12, 2012

Apply only this patch.

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 12, 2012

Changed reviewer from Sébastien Labbé to none

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 12, 2012

comment:11

Attachment: trac_12351-doctest.patch.gz

The new code from #10998 already uses have_same_parent. So all that's left to do here is to add a doctest to prevent the error happening again. I've uploaded a patch for that.

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 12, 2012

Changed author from Simon King to David Loeffler

@nthiery
Copy link
Contributor

nthiery commented Mar 12, 2012

Reviewer: Nicolas M. Thiéry, Simon King

@jdemeyer
Copy link

Merged: sage-5.0.beta9

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

No branches or pull requests

4 participants