Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update handling of colnames #149

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Update handling of colnames #149

wants to merge 20 commits into from

Conversation

oruebel
Copy link
Contributor

@oruebel oruebel commented Jan 31, 2025

This PR updates the handling of the DynamicTable.colNames to: 1) avoid the need for specifying colNames at the beginning and 2) to allow us to dynamically add columns to a DynamicTable (even one that was read from a file)

Related issues

Fix #107
Fix #150
Fix #129

Fixed writing of variable-length string attributes and VectorData columns:

  • Fixed writing of Attributes that are arrays of variable-length
    • Write string array attributes as variable length string arrays instead of fixed length string arrays
    • Updated BaseIO.createAttribute for string arrays to explicitly allow us to force overwrite of existing attributes and updated HDF5IO.createAttribute accordingly. HDF5 does not support expanding attributes in the same way it does for datasets so we need to delete the existing attribute and overwrite it with a new one with the same name.
  • Fixed writing of variable-length strings columns via DynamicTable.add_column to avoid unnecessary iteration and use writeDataBlock directly
  • Fixed data types for string columns in ElectrodeTable to use variable length strings instead of fixed length strings

Improved handling of Status

  • Return the Status for DynamicTable functions that perform write operations (e.g,. initialize, finalize, add_column etc.) as well as relevant other classes, e.g., Data, VectorData, Container ...
  • Defined && and || operator for the Status enum to simplify combining multiple Status checks

Updated handling of colNames to correctly handle dynamic adding of columns

  • Delayed writing of colNames to the end by adding DynamicTable.finalize akin to the existing ElectrodeTable.finalize. This allows for columns to be added to the DynamicTable
    • Updated DynamicTable.finalize to overwrite column names to correctly support appending of columns to existing tables
  • Updated DynamicTable constructor to read the existing column names if they exist from the file so that we can append new columns to existing tables

Updated unit tests

  • Updated unit tests for HDF5IO.createAttribute
  • Added new unit tests for DynamicTable
  • Enhanced ElectrodeTable unit tests to appropriately check for the status of write operations and fix existing failing tests due to missing Device and ElectrodeGroup

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 93.94813% with 21 lines in your changes missing coverage. Please review.

Project coverage is 93.23%. Comparing base (00a529c) to head (d69d55c).

Files with missing lines Patch % Lines
src/io/hdf5/HDF5IO.cpp 66.66% 16 Missing ⚠️
src/nwb/hdmf/table/DynamicTable.cpp 91.89% 3 Missing ⚠️
src/Types.hpp 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #149      +/-   ##
==========================================
+ Coverage   93.20%   93.23%   +0.02%     
==========================================
  Files          62       64       +2     
  Lines        4328     4595     +267     
  Branches      268      271       +3     
==========================================
+ Hits         4034     4284     +250     
- Misses        284      301      +17     
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oruebel oruebel requested a review from stephprince January 31, 2025 02:18
@oruebel
Copy link
Contributor Author

oruebel commented Feb 3, 2025

@stephprince this PR is ready for review

Copy link
Collaborator

@stephprince stephprince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks. I just had a question about the overwriting of variable length strings but all of the electrodes table and column changes look good to me.

@@ -683,17 +683,82 @@ Status HDF5IO::createAttribute(const std::string& data,

Status HDF5IO::createAttribute(const std::vector<std::string>& data,
const std::string& path,
const std::string& name)
const std::string& name,
const bool overwrite)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I am just wondering if there was a specific reason to add the overwrite functionality on this function instead of the version of the createAttribute function defined below:

Status HDF5IO::createAttribute(const std::vector<const char*>& data,
                               const std::string& path,
                               const std::string& name,
                               const SizeType& maxSize)

Since that version is used during both single string and string array attribute creation and performs similar checks for the attribute already existing?


/**
* @brief Creates a string array attribute at a given location in the file.
* @brief Creates a fixed-length string array attribute at a given location in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding this function writes variable length string arrays:

H5type.setSize(H5T_VARIABLE);

However, I think it is maybe unclear since a maximum size is accepted, but this parameter is then overwritten. I'm not sure why that is the case....

@@ -40,41 +40,27 @@ class ElectrodeTable : public DynamicTable
* Initializes the ElectrodeTable by creating NWB related attributes and
* adding required columns.
*
* @param description The description of the table (default: "metadata about
* @param description The description of the table (default: "metadata about
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param description The description of the table (default: "metadata about
* @param description The description of the table (default: "metadata about extracellular electrodes")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants