Skip to content

[WIP] Support get_class and roundtrip on datetime datasets#1313

Draft
rly wants to merge 14 commits intodevfrom
get_class_datetime
Draft

[WIP] Support get_class and roundtrip on datetime datasets#1313
rly wants to merge 14 commits intodevfrom
get_class_datetime

Conversation

@rly
Copy link
Copy Markdown
Contributor

@rly rly commented Sep 19, 2025

Motivation

Fix #429. Related to #1312.

How to test the behavior?

Show how to reproduce the new behavior (can be a bug fix or a new feature)

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?

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 73.13433% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.02%. Comparing base (f82893b) to head (f8a0e07).

Files with missing lines Patch % Lines
src/hdmf/build/objectmapper.py 65.00% 8 Missing and 6 partials ⚠️
src/hdmf/build/classgenerator.py 80.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1313      +/-   ##
==========================================
- Coverage   93.17%   93.02%   -0.15%     
==========================================
  Files          41       41              
  Lines       10099    10143      +44     
  Branches     2079     2093      +14     
==========================================
+ Hits         9410     9436      +26     
- Misses        413      423      +10     
- Partials      276      284       +8     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

rly and others added 11 commits February 11, 2026 22:14
_isoformat was returning a Python str while convert_dtype labeled the
result as the 'ascii' dtype. Encode to bytes (matching _ascii's contract)
so the scalar branch produces the expected b'YYYY-MM-DDTHH:MM:SS' values.
Also handle str and bytes passthrough for idempotence when __convert_string
has already pre-converted the value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add Column (Data) and BarWithColumnData (Container) helper classes and
two tests exercising build of datetime/date values through a dataset
spec with data_type_inc set. test_date_array_ext_spec specifically
mirrors the traceback in #1311.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add _parse_isoformat helper (reverse of _isoformat) and wire it into
__get_subspec_values so attributes and dataset data with isodatetime/datetime
dtype are converted from stored ISO str/bytes back into datetime/date before
being passed to the container constructor. Also applied to Data containers'
direct const_args['data'] assignment in construct().

Scoped to scalar values; inc-site dtype override and array datasets are not
yet handled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Pass ignore_name/ignore_hdmf_attrs to assertContainerEqual so the
  top-level 'root' vs 'my_group' name mismatch and read-time object_id
  reassignment don't fail the equality check.
- my_data3 has no data_type_inc, so it is stored as a named scalar
  dataset field on the group and read back as a plain datetime value.
  Assert against the value directly rather than .data.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
construct() now accepts an optional spec_ext (parallel to build()) that
carries per-site overrides from the parent's subspec. Threaded through
BuildManager.construct, TypeMap.construct, and ObjectMapper.construct.

The Data-container construct path uses spec_ext for dtype resolution when
the base def has no dtype, so a parent group spec like
    DatasetSpec(data_type_inc='X', dtype='datetime', ...)
correctly drives datetime parsing on read even when X's def declares no
dtype. __get_sub_builders passes the inc-site subspec as spec_ext at the
construct call site.

spec_ext defaults to None to preserve backward compatibility with all
existing call sites.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Data containers can wrap scalar values (e.g., a single datetime) for which
len() is not defined. Gate the length comparison on _is_collection so the
helper works for both scalar and collection-valued Data instances.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
scalar_data now includes datetime.datetime and datetime.date so generated
classes for dtype-less DatasetSpecs accept scalar datetime values on
construct (read path) and on user-side construction (write path).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

get_class to handle datetimes

1 participant