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

DM-43769: Improve Pydantic support for sphgeom.Region and Timespan #997

Merged
merged 10 commits into from Apr 13, 2024

Conversation

TallJimbo
Copy link
Member

@TallJimbo TallJimbo commented Apr 11, 2024

Checklist

  • ran Jenkins (in progress)
  • added a release note for user-visible changes to doc/changes
  • (if changing dimensions.yaml) make a copy of dimensions.yaml in configs/old_dimensions

Copy link

codecov bot commented Apr 11, 2024

Codecov Report

Attention: Patch coverage is 92.90780% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 88.97%. Comparing base (651340a) to head (ad25039).

Files Patch % Lines
python/lsst/daf/butler/dimensions/_records.py 66.66% 2 Missing and 2 partials ⚠️
python/lsst/daf/butler/pydantic_utils.py 82.60% 2 Missing and 2 partials ⚠️
python/lsst/daf/butler/_timespan.py 95.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #997      +/-   ##
==========================================
- Coverage   88.98%   88.97%   -0.01%     
==========================================
  Files         344      344              
  Lines       44141    44199      +58     
  Branches     9084     9100      +16     
==========================================
+ Hits        39278    39326      +48     
- Misses       3549     3556       +7     
- Partials     1314     1317       +3     

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

@TallJimbo TallJimbo force-pushed the tickets/DM-43769 branch 2 times, most recently from c1cfd21 to ce88844 Compare April 12, 2024 16:07
Copy link
Contributor

@dhirving dhirving left a comment

Choose a reason for hiding this comment

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

Looks alright to me. I suggested a possible implementation that doesn't require resorting to pydantic core. Whether this is easier to understand is a matter of taste, so take it or leave it. 🤷

python/lsst/daf/butler/pydantic_utils.py Outdated Show resolved Hide resolved
python/lsst/daf/butler/pydantic_utils.py Outdated Show resolved Hide resolved
adapter.validate_json({})
with self.assertRaises(ValueError):
adapter.validate_json((b"this is not a region").hex())

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a test for "a string, but not a hex string." (Pretty sure it will pass already.)

@dhirving
Copy link
Contributor

Also in the future feel free to delegate any little tickets like this to me, I'm sure you have much bigger fish to fry :D

TallJimbo and others added 10 commits April 12, 2024 17:14
Pydantic's symbols (especially Field) often aren't obviously from
Pydantic on their own, so I think it's one of the cases where
'import pydantic' is better than 'from pydantic import <stuff>',
especially when '<stuff>' is long, as it is about to become here.
This cleaned up some special-casing in DimensionRecord serialization,
but it required some other special-casing to be replaced, for two
primary reasons:

- The 'direct' deserialization methods (which we *may* not even need)
  is hashing entire proto-records in its cache system, while it should
  just be using required-dimension-value tuples.

- I haven't tried to replace the special-casing for 'region' and
  'hash' (this one really bakes in some bad assumptions about the
  concrete universe!).

I have thoughts for addressing both issues but I think they're more
than I want to do on this branch.
This requires making Timespan.nsec public, which is only slightly
unfortunate; we can declare it frozen to maintain immutability, and
we couldn't realistically change the implementation in the future given
that we've already exposed that in how it's serialized.

This obsoletes the previous commit on this branch that used
pydantic_core, but I'm keeping that version in the commit history in
case it's meaningfully more efficient in validation or memory use (I
suspect it's slightly more efficient, but not enough to matter).
Co-authored-by: David H. Irving <david.irving@noirlab.edu>
Co-authored-by: David H. Irving <david.irving@noirlab.edu>
@TallJimbo TallJimbo merged commit 0b47594 into main Apr 13, 2024
18 checks passed
@TallJimbo TallJimbo deleted the tickets/DM-43769 branch April 13, 2024 01:22
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.

None yet

2 participants