Skip to content

Commit

Permalink
Allow SchemaMapper as positional argument to Catalog.extend
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Dec 31, 2014
1 parent ae20e2b commit 415bc6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions python/lsst/afw/table/Catalog.i
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public:
self->insert(mapper, self->end(), other.begin(), other.end());
}
%feature("shadow") extend %{
def extend(self, iterable, deep=None, mapper=None):
def extend(self, iterable, mapper=None, deep=None):
"""Append all records in the given iterable to the catalog.
Arguments:
iterable ------ any Python iterable containing records
mapper -------- a SchemaMapper object used to translate records
deep ---------- if True, the records will be deep-copied; ignored
if mapper is not None (that always implies True).
mapper -------- a SchemaMapper object used to translate records
"""
self._columns = None
if isinstance(iterable, type(self)):
Expand All @@ -106,6 +106,9 @@ public:
else:
$action(self, iterable, deep)
else:
if not isinstance(mapper, SchemaMapper):
deep = mapper
mapper = None
for record in iterable:
if mapper is not None:
self.append(self.table.copyRecord(record, mapper))
Expand Down
8 changes: 6 additions & 2 deletions tests/testSimpleTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,14 @@ def testExtend(self):
cat6.extend(list(cat1), mapper=mapper)
self.assertFalse(cat6.isContiguous())
cat7 = lsst.afw.table.SourceCatalog(schema2)
cat7.reserve(len(cat1) * 2)
cat7.reserve(len(cat1) * 3)
cat7.extend(list(cat1), mapper=mapper)
cat7.extend(cat1, mapper=mapper)
cat7.extend(cat1, mapper)
cat7.extend(list(cat1), mapper)
self.assert_(cat7.isContiguous())
cat8 = lsst.afw.table.BaseCatalog(schema2)
cat8.extend(list(cat7), True)
cat8.extend(list(cat7), deep=True)

def testTicket2308(self):
inputSchema = lsst.afw.table.SourceTable.makeMinimalSchema()
Expand Down

0 comments on commit 415bc6d

Please sign in to comment.