Skip to content

Conversation

@tdh2005
Copy link

@tdh2005 tdh2005 commented Sep 18, 2025

Updates #1701:
This update modifies 3 files; constraints.py, test_constraints.py and test.read.py.

Modifications:

  1. Constraints.py: Commits modifying this file have added the function 'my_pdt_fromstring()' which parses out am ISO date string into temporal coordinates (year, month, day, hour, minute and second) to return a PartialDateTime object to replicate the 'fromisoformat()' method. The function for 'generate_time_constraint()' is also modified such to use 'my_pdt_fromstring()' rather than 'fromisoformat()'. This has therefore allowed for the ability to process files with more idealised calendars included in CF Metadata convention (eg. 360 day).

  2. test_constraint.py: A series of test functions have been written to test the 'my_pdt_fromstring()' function added to constraints.py. These verify the function is able to correctly parse a given date string and return a PartialDateTtime.

  3. test_read.py: A test function named 'test_read_cubes_generate_time_constraint()' verifies that a cube can be read and correctly constrained along the time coordinate.

NOTE: the test function added to test_read.py uses a NetCDF file that has not been included in the pull request. The file in question has a size of 24 KB, similar to other data files included within the test_data folder and uses a 360 day calendar. We would like to further ask for further approval to add this.

@tdh2005 tdh2005 requested a review from jfrost-mo September 18, 2025 15:39
Copy link
Member

@jfrost-mo jfrost-mo left a comment

Choose a reason for hiding this comment

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

Looks like a sensible approach. I've suggested some additional date strings to add as tests, which I think will require some changes to your date parser.

Copy link
Member

@jfrost-mo jfrost-mo Sep 24, 2025

Choose a reason for hiding this comment

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

We want to support the full range of ISO 8601 dates. Additional test cases to add:

  • Basic format: 20250924
  • Basic format with time: 20250924T0921Z
  • Month precision: 2025-09
  • Microseconds: 2025-09-24T09:21:42.123456
  • Alternate UTC representation: 2025-09-24T09:21+00:00
  • Indian Standard Time: 2025-09-24T09:21+05:30

We probably don't need to support week dates (2025-W01) or ordinal dates (2025-365).

Copy link
Member

Choose a reason for hiding this comment

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

There shouldn't be any issue adding a 24 KiB test file. Stick it somewhere under tests/test_data/.

tdh2005 added a commit that referenced this pull request Oct 10, 2025
file name changed in test_read.py file
… test.read.py.

Modifications:

Constraints.py: Commits modifying this file have added the function 'my_pdt_fromstring()' which parses out am ISO date string into temporal coordinates (year, month, day, hour, minute and second) to return a PartialDateTime object to replicate the 'fromisoformat()' method. The function for 'generate_time_constraint()' is also modified such to use 'my_pdt_fromstring()' rather than 'fromisoformat()'. This has therefore allowed for the ability to process files with more idealised calendars included in CF Metadata convention (eg. 360 day).

test_constraint.py: A series of test functions have been written to test the 'my_pdt_fromstring()' function added to constraints.py. These verify the function is able to correctly parse a given date string and return a PartialDateTtime.

test_read.py: A test function named 'test_read_cubes_generate_time_constraint()' verifies that a cube can be read and correctly constrained along the time coordinate.

NOTE: the test function added to test_read.py uses a NetCDF file that has not been included in the pull request. The file in question has a size of 24 KB, similar to other data files included within the test_data folder and uses a 360 day calendar. We would like to further ask for further approval to add this.
Fixes #1701
@tdh2005 tdh2005 force-pushed the operator-constraint-update branch from 052b90a to 41e26e1 Compare October 10, 2025 15:24
@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2025

Coverage

Constraints.py: This commit modifies the file to add wider support for offset formats (e.g. hh, hhmm, hh:mm) with the my_pdt_fromstring() function.
constraints.py: Format of pdt output changed for special case YYYY-MM for the my_pdt_fromstring() function.

test_constraints.py: asserts modified for the special case YYYY-MM test to reflect changes to my_pdt_fromstring() function.

test_read.py: More specific asserts added to the test_read_cubes_generate_time_constraint() test to reflect file properties.
@tdh2005 tdh2005 requested a review from jfrost-mo October 14, 2025 13:23
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