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

Don't override col_cls in DynamicTable.add_column #1091

Merged
merged 14 commits into from
Jan 22, 2025
Merged

Don't override col_cls in DynamicTable.add_column #1091

merged 14 commits into from
Jan 22, 2025

Conversation

rly
Copy link
Contributor

@rly rly commented Apr 4, 2024

Motivation

Issue: If a user creates a schema that extends DynamicTableRegion or EnumData and tries to create a column with that subclass as the column class, the column is instead created with the base DynamicTableRegion or EnumData class.

For example, if a user creates a new type CustomDTR that extends the DynamicTableRegion type, and then they create a DynamicTable and calls add_column with the column class being set to the new type (col_cls=CustomDTR), then the new column for this table currently has type DynamicTableRegion.

    test_table.add_column(
            name='custom_dtr_column',
            description='this is a custom DynamicTableRegion column',
            col_cls=self.CustomDTR,
            table=True,
        )

See new test: test_add_custom_dtr_column

Another use case: if a user creates a new type CustomDTR that extends the DynamicTableRegion type, and they create a new type CustomTable that extends DynamicTable and contains a column with type CustomDTR, then the auto-generated column for this table currently has type DynamicTableRegion.

See test: test_custom_dtr_class

To make this work correctly in this PR, I updated add_column to use the passed col_cls instead of assuming table=True means col_cls=DynamicTableRegion. In order to do that, I also had to change the default value for col_cls away from VectorData. That default was set in more places than was needed anyway. I also had to move when the check that the passed col_cls equals the class included in a pre-defined column in __columns__ occurs, so that it is checked after col_cls is appropriately set, not before.

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Does the PR clearly describe the problem and the solution?
  • Have you reviewed our Contributing Guide?
  • Does the PR use "Fix #XXX" notation to tell GitHub to close the relevant issue numbered XXX when the PR is merged?

@mavaylon1
Copy link
Contributor

Will this be in by next milestone?

@VisLab
Copy link

VisLab commented Apr 26, 2024

Please let us know when it gets in. We are relying on it for implementation of ndx-hed.

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.87%. Comparing base (775fa3b) to head (a5b6671).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
src/hdmf/common/table.py 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1091      +/-   ##
==========================================
- Coverage   90.88%   90.87%   -0.01%     
==========================================
  Files          42       42              
  Lines        9532     9537       +5     
  Branches     1922     1926       +4     
==========================================
+ Hits         8663     8667       +4     
  Misses        576      576              
- Partials      293      294       +1     

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

@rly rly marked this pull request as ready for review January 21, 2025 22:07
@rly rly requested a review from mavaylon1 January 21, 2025 22:16
@rly rly enabled auto-merge (squash) January 21, 2025 23:31
@rly rly merged commit ab8cf3b into dev Jan 22, 2025
27 checks passed
@rly rly deleted the rly-patch-1 branch January 22, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants