TopoNetX icon indicating copy to clipboard operation
TopoNetX copied to clipboard

Inconsistencies in `__contains__` implementation across complex types

Open ffl096 opened this issue 2 years ago • 2 comments

The function __contains__ is not consistently implemented across different complex types:

  • For cell and combinatorial complexes, it checks whether a node exists.
  • For simplicial and path complexes, it checks whether an atom (nodes but also higher-order) exists.

The Complex ABC documents that __contains__ checks whether the complex contains an item (i.e., simplicial and path complexes are correct).

ffl096 avatar Oct 09 '23 14:10 ffl096

@ffl096 there is an issue here though. Iter iterates only over nodes now consistent with NetworkX (we just closed this issue recently ). So it would make more sense to make __getitem__ also works same way? namely it will only check if a node is in the complex. If one wants to check if an item is in the complex then one should check in CC.cells or PC.paths or SC.simplices, also consistent with NetworkX, what do you think?

mhajij avatar Oct 13 '23 04:10 mhajij

I agree on that, __iter__, __contains__ and so on should be consistent in that a complex does not "contain" something that is not iterated over ect. We have to update the documentation of Complex.__contains__ for that.

ffl096 avatar Oct 13 '23 07:10 ffl096