Skip to content

Commit decb84f

Browse files
committed
alternate hidden attr implementation
1 parent 99c9ea8 commit decb84f

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

datajoint/fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def __call__(
286286
ret = np.array(ret, dtype=record_type)
287287
except Exception as e:
288288
raise e
289-
for name in heading:
289+
for name in heading.names:
290290
# unpack blobs and externals
291291
ret[name] = list(map(partial(get, heading[name]), ret[name]))
292292
if format == "frame":

datajoint/heading.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
is_attachment=False,
3434
is_filepath=False,
3535
is_external=False,
36+
is_hidden=False,
3637
adapter=None,
3738
store=None,
3839
unsupported=False,
@@ -124,32 +125,37 @@ def attributes(self):
124125

125126
@property
126127
def names(self):
127-
return [k for k in self.attributes]
128+
return [k for k in self.attributes if not self.attributes[k].is_hidden]
128129

129130
@property
130131
def primary_key(self):
131-
return [k for k, v in self.attributes.items() if v.in_key]
132+
return [k for k, v in self.attributes.items() if v.in_key and not v.is_hidden]
132133

133134
@property
134135
def secondary_attributes(self):
135-
return [k for k, v in self.attributes.items() if not v.in_key]
136+
return [
137+
k for k, v in self.attributes.items() if not v.in_key and not v.is_hidden
138+
]
136139

137140
@property
138141
def blobs(self):
139-
return [k for k, v in self.attributes.items() if v.is_blob]
142+
return [k for k, v in self.attributes.items() if v.is_blob and not v.is_hidden]
140143

141144
@property
142145
def non_blobs(self):
143146
return [
144147
k
145148
for k, v in self.attributes.items()
146149
if not (v.is_blob or v.is_attachment or v.is_filepath or v.json)
150+
and not v.is_hidden
147151
]
148152

149153
@property
150154
def new_attributes(self):
151155
return [
152-
k for k, v in self.attributes.items() if v.attribute_expression is not None
156+
k
157+
for k, v in self.attributes.items()
158+
if v.attribute_expression is not None and not v.is_hidden
153159
]
154160

155161
def __getitem__(self, name):
@@ -165,6 +171,8 @@ def __repr__(self):
165171
if self._table_status is not None:
166172
ret += "# " + self.table_status["comment"] + "\n"
167173
for v in self.attributes.values():
174+
if v.is_hidden:
175+
continue
168176
if in_key and not v.in_key:
169177
ret += "---\n"
170178
in_key = False
@@ -298,6 +306,7 @@ def _init_from_database(self):
298306
store=None,
299307
is_external=False,
300308
attribute_expression=None,
309+
is_hidden=attr["name"].startswith("_"),
301310
)
302311

303312
if any(TYPE_PATTERN[t].match(attr["type"]) for t in ("INTEGER", "FLOAT")):

datajoint/table.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ def describe(self, context=None, printout=False):
711711
attributes_declared = set()
712712
indexes = self.heading.indexes.copy()
713713
for attr in self.heading.attributes.values():
714+
if attr.is_hidden:
715+
continue
714716
if in_key and not attr.in_key:
715717
definition += "---\n"
716718
in_key = False
@@ -857,7 +859,7 @@ def check_fields(fields):
857859
raise KeyError(
858860
"`{0:s}` is not in the table heading".format(field)
859861
)
860-
elif set(field_list) != set(fields).intersection(self.heading.names):
862+
elif set(field_list) != set(fields).intersection(self.heading):
861863
raise DataJointError("Attempt to insert rows with different fields.")
862864

863865
if isinstance(row, np.void): # np.array

0 commit comments

Comments
 (0)