Skip to content

Commit

Permalink
add section on enumerated data to docs (#568)
Browse files Browse the repository at this point in the history
* add section on enumerated data to docs

* Update src/hdmf/common/table.py
  • Loading branch information
bendichter authored Apr 13, 2021
1 parent 777b230 commit 9d85db1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
33 changes: 27 additions & 6 deletions docs/gallery/dynamictable.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,35 @@
data=[True, True, False, True], # specify data for the 4 rows in the table
)

###############################################################################
# Enumerated Data
# ---------------
# :py:class:`~hdmf.common.table.EnumData` is a special type of column for storing
# an enumerated data type. This way each unique value is stored once, and the data
# references those values by index. Using this method is more efficient than storing
# a single value many types, and has the advantage of communicating to downstream
# tools that the data is categorical in nature.

from hdmf.common.table import EnumData

# this column has a length of 5, not 3
enum_col = EnumData(
name="cell_type",
description="this column holds categorical variables",
data=[0, 1, 2, 1, 0],
elements=["aa", "bb", "cc"]
)

my_table = DynamicTable(
name='my table',
description='an example table',
columns=[enum_col],
)


###############################################################################
# Ragged array columns
# ^^^^^^^^^^^^^^^^^^^^
# --------------------
# A table column with a different number of elements for each row is called a
# ragged array. To initialize a :py:class:`~hdmf.common.table.DynamicTable`
# with a ragged array column, pass both
Expand Down Expand Up @@ -598,11 +624,6 @@
table_double_ragged_col['col6'] # returns col6_ind_ind
table_double_ragged_col.col6 # returns col6

###############################################################################
# Referencing rows of a DynamicTable
# ----------------------------------
# TODO

###############################################################################
# Creating custom DynamicTable subclasses
# ---------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/hdmf/common/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,12 +1180,12 @@ class EnumData(VectorData):

__fields__ = ('elements', )

@docval({'name': 'name', 'type': str, 'doc': 'the name of this VectorData'},
@docval({'name': 'name', 'type': str, 'doc': 'the name of this column'},
{'name': 'description', 'type': str, 'doc': 'a description for this column'},
{'name': 'data', 'type': ('array_data', 'data'),
'doc': 'a dataset where the first dimension is a concatenation of multiple vectors', 'default': list()},
'doc': 'integers that index into elements for the value of each row', 'default': list()},
{'name': 'elements', 'type': ('array_data', 'data', VectorData), 'default': list(),
'doc': 'the items in this elements'})
'doc': 'lookup values for each integer in ``data``'})
def __init__(self, **kwargs):
elements = popargs('elements', kwargs)
super().__init__(**kwargs)
Expand Down

0 comments on commit 9d85db1

Please sign in to comment.