Opened 9 years ago

Closed 9 years ago

#12351 closed defect (fixed)

AttributeError raised by method __eq__ of poset element

Reported by: slabbe Owned by: slabbe
Priority: major Milestone: sage-5.0
Component: combinatorics Keywords: poset
Cc: sage-combinat Merged in: sage-5.0.beta9
Authors: David Loeffler Reviewers: Nicolas M. Thiéry, Simon King
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by slabbe)

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'

Attachments (1)

trac_12351-doctest.patch (765 bytes) - added by davidloeffler 9 years ago.
Apply only this patch.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 9 years ago by SimonKing

  • Authors set to Simon King
  • Status changed from new to needs_review

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!

comment:2 follow-up: Changed 9 years ago by slabbe

  • Reviewers set to Sébastien Labbé
  • Status changed from needs_review to positive_review

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'

comment:3 in reply to: ↑ 2 Changed 9 years ago by slabbe

But now, I get another problem.

This is now #12364.

comment:4 Changed 9 years ago by slabbe

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

comment:5 follow-up: Changed 9 years ago by slabbe

  • Description modified (diff)
  • Owner changed from sage-combinat to slabbe
  • Summary changed from AttributeError when ploting a poset to AttributeError raised by method __eq__ of poset element

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

comment:6 in reply to: ↑ 5 ; follow-up: Changed 9 years ago by nthiery

  • Status changed from positive_review to needs_work

Replying to slabbe:

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.

comment:7 in reply to: ↑ 6 Changed 9 years ago by SimonKing

Replying to nthiery:

Replying to slabbe:

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.

comment:8 Changed 9 years ago by SimonKing

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

comment:9 follow-up: Changed 9 years ago by SimonKing

  • Status changed from needs_work to needs_review

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.

comment:10 in reply to: ↑ 9 Changed 9 years ago by nthiery

Replying to SimonKing:

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".

Changed 9 years ago by davidloeffler

Apply only this patch.

comment:11 Changed 9 years ago by davidloeffler

  • Authors changed from Simon King to David Loeffler
  • Reviewers Sébastien Labbé deleted

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.

comment:12 Changed 9 years ago by nthiery

  • Reviewers set to Nicolas M. Thiéry, Simon King
  • Status changed from needs_review to positive_review

comment:13 Changed 9 years ago by jdemeyer

  • Merged in set to sage-5.0.beta9
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.