Skip to content

Commit 5a012ec

Browse files
authored
Merge pull request #777 from lsst/tickets/DM-49695
DM-49695: Allow hasattr to work for table for dunder properties if non-contiguous
2 parents 271391e + 32d1724 commit 5a012ec

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

python/lsst/afw/table/_base.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,17 @@ def __getattr__(self, name):
339339
try:
340340
return getattr(self.table, name)
341341
except AttributeError:
342-
return getattr(self.columns, name)
342+
# Special case __ properties as they are never going to be column
343+
# names.
344+
if name.startswith("__"):
345+
raise
346+
# This can fail if the table is non-contiguous
347+
try:
348+
attr = getattr(self.columns, name)
349+
except Exception as e:
350+
e.add_note(f"Error retrieving column attribute '{name}' from {type(self)}")
351+
raise
352+
return attr
343353

344354
def __str__(self):
345355
if self.isContiguous():

tests/test_simpleTable.py

+5
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ def testAngleColumnArrayAccess(self):
817817
self.assertFloatsEqual(catalog[key], np.array([3.0, 4.0, 5.0]))
818818
self.assertFalse(catalog[key].flags.writeable)
819819

820+
# Test that non-contiugous catalog can support hasattr of missing
821+
# attributes.
822+
self.assertFalse(hasattr(catalog, "__qualname__"))
823+
self.assertTrue(hasattr(type(catalog), "__qualname__"))
824+
820825
def testArrayColumnArrayAccess(self):
821826
"""Test column-array access to Array columns on both contiguous and
822827
non-contiguous arrays.

0 commit comments

Comments
 (0)