From feb30703c4be9aa1e840a13d18d07a6c8f67878e Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Wed, 26 Jul 2023 00:50:45 -0700 Subject: [PATCH] Relax error check for missing columns in DynamicTable.__init__ when reading from file --- src/hdmf/common/table.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hdmf/common/table.py b/src/hdmf/common/table.py index 1b4fe76d1..7f84787ed 100644 --- a/src/hdmf/common/table.py +++ b/src/hdmf/common/table.py @@ -394,7 +394,16 @@ def __init__(self, **kwargs): # noqa: C901 else: # Calculate the order of column names if columns is None: - raise ValueError("Must supply 'columns' if specifying 'colnames'") + # Invalid table. Custom colnames are given but the VectorData for those columns are missing. + if self._in_construct_mode: # Relax error checking when reading from an existing file + # To allow reading of bad files and since we don't have any actual data for the + # custom columns, we can try to just ignore the columns and warn instead of raising a ValueError. + self.colnames = tuple() + self.columns = tuple() + warn("Ignoring custom named columns. Must supply 'columns' if specifying" + " 'colnames'=%s for table name=%s" % (str(colnames), self.name)) + else: # be strict when constructing a new table + raise ValueError("Must supply 'columns' if specifying 'colnames'") else: # order the columns according to the column names, which does not include indices self.colnames = tuple(pystr(c) for c in colnames)