Skip to content

Commit

Permalink
REVIEWME: custom __iter__, iterates over rows, breaks pandas contract.
Browse files Browse the repository at this point in the history
Only pandas' __str__ and __repr__ used iteration over rows, our tests
pass either way. This is a very high-level decision which needs the
concensus of the whole group.
  • Loading branch information
sstanovnik committed Aug 12, 2016
1 parent 686a68b commit 68b18c5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Orange/data/table/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,28 @@ def __setitem__(self, key, value):
# super call because we'd otherwise recurse back into this
super().__setitem__(self._WEIGHTS_COLUMN, 1)

def __iter__(self):
"""Iterate over the rows of this TableBase as SeriesBase, breaking the pandas contract.
Returns
-------
generator
A generator of rows as SeriesBase objects.
Examples
--------
>>> iris = Table('iris')
>>> for row in iris.iloc[:5]:
>>> print(row)
Notes
-----
This breaks the pandas contract! Pandas iterates over column names by default.
However, this only breaks __str__ and __repr__, which are reimplemented anyway.
"""
for _, row in self.iterrows():
yield row

def __str__(self):
"""Override the pandas representation to provide a more Orange-friendly one."""
max_displayed_rows = 30
Expand Down

0 comments on commit 68b18c5

Please sign in to comment.