Skip to content

fix: make tests more lenient with changing serialization of timestamps - #382

Merged
fuchsi-huber merged 4 commits into
mainfrom
fix/timestamp-in-tests
Sep 2, 2026
Merged

fuchsi-huber merged 4 commits into
mainfrom
fix/timestamp-in-tests

Conversation

@fuchsi-huber

@fuchsi-huber fuchsi-huber commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Pull request

Please confirm that this pull request has done the following:

  • Tests added
  • Documentation added (where applicable)
  • Description in a {pr}.thing.md file in the directory changelog added - see changelog/README.md for details

Description

A few tests failed due to inconsistent precision of timestamps (6 vs. 9 positions after the seconds). Reduced the checks in the tests to the essential part that ensures that the correct failure branch was taken.

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@d373f99). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #382   +/-   ##
=======================================
  Coverage        ?   97.29%           
=======================================
  Files           ?       54           
  Lines           ?     5361           
  Branches        ?        0           
=======================================
  Hits            ?     5216           
  Misses          ?      145           
  Partials        ?        0           

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

@fuchsi-huber
fuchsi-huber force-pushed the fix/timestamp-in-tests branch from 2f59c5e to f2e5599 Compare August 31, 2026 14:20
Comment thread primap2/_setters.py Outdated
Traceback (most recent call last):
...
ValueError: Values {'MEX'} for 'area (ISO3)' already exist and contain data. ...
ValueError: Values {...} for 'area (ISO3)' already exist and contain data. ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, that is a case which makes the example significantly worse to read for a human, right? Knowing that the value which already exists is MEX and not confusingly ARG or so is actually quite helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, but then we need to change either the generation of the ValueError (to print __str__ instead of __repr__) or the example to not rely on the exception. The shown value is 'MEX in older versions of numpy and np.str_('MEX') in newer versions

@fuchsi-huber fuchsi-huber Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A similar problem arises from the DataArray serialization. the expected <Quantity([0.4 0.9 1.7 4.8 3.2 9.1], 'hertz')> is actually Quantity(array([0.4, 0.9, 1.7, 4.8, 3.2, 9.1]), "hertz") in the development xarray versions... I don't think we can maintain this doctest across so many different library versions without reducing the output in the documentation to generics like ...Quantity...hertz... which are really hard to parse for humans. A couple of options I see:

  1. as we talked about: remove the examples from the documentation, add them as unit-tests (or similar) instead and reference those tests in the docs
  2. don't check output in the doctests, only that the provided code actually runs and throws exceptions when it is supposed to (which is honestly what we would also do if they are unit tests instead?)
  3. restrict the doctests to a single test environment and update the expected output from time to time to match the output in that single test environment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have ignored the exception detail for the mentioned examples and fixed the still failing tests by making them a bit more robust. I guess we have to make these examples not rely on the repr so much in the future.

For now this should pass all tests - though it probably is still not super robust

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, using str() instead of repr() in the ValueError is sensible, I think, in this specific instance. But more generally, I think we might drop doctests. A pity, but not feasible given how much work it creates.

…umented function; reverted to more helpful docstring examples
@fuchsi-huber
fuchsi-huber merged commit 09e617e into main Sep 2, 2026
13 of 14 checks passed
@fuchsi-huber
fuchsi-huber deleted the fix/timestamp-in-tests branch September 2, 2026 10:45
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.

2 participants