def test_where_preserves_rows(self): table = Table(self.rows, self.columns) table2 = table.where(lambda r: r['one'] == 1) table3 = table2.where(lambda r: r['one'] == 1) self.assertIs(table.rows[0], table2.rows[0]) self.assertIs(table2.rows[0], table3.rows[0])
def test_where(self): table = Table(self.rows, self.columns) new_table = table.where(lambda r: r['one'] in (2, None)) self.assertIsNot(new_table, table) self.assertEqual(len(new_table.rows), 2) self.assertSequenceEqual(new_table.rows[0], (2, 3, 'b')) self.assertSequenceEqual(new_table.columns['one'], (2, None))
def test_where_with_row_names(self): table = Table(self.rows, self.columns, row_names='three') new_table = table.where(lambda r: r['one'] in (2, None)) self.assertSequenceEqual(table.rows['a'], (1, 4, 'a')) self.assertSequenceEqual(new_table.row_names, ('b', u'👍'))