Skip to content

Conversation

@chengzhuzhang
Copy link
Contributor

Description

Branch from #972

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have added tests that prove my fix is effective or that my feature works
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@chengzhuzhang
Copy link
Contributor Author

chengzhuzhang commented May 1, 2025

@tomvothecoder, inspired by your comment #972 (comment). I attempted this implementation, though there is still somehow the online CI/CD test errors. Maybe we should go for this approach, that is more automatic?

I'm trying to fix my local environment to match the CI env, to have consistent results, any suggestion is appreciated!

@tomvothecoder
Copy link
Collaborator

@tomvothecoder, inspired by your comment #972 (comment). I attempted this implementation, though there is still somehow the online CI/CD test errors. Maybe we should go for this approach, that is more automatic?

I'm trying to fix my local environment to match the CI env, to have consistent results, any suggestion is appreciated!

Thanks for building on my PR! Yes, an automated way of detecting when to pad years is a great idea.

I'll review your PR when I get the chance.

tomvothecoder and others added 6 commits May 9, 2025 14:11
Update references to use `pad_year` where time slicing is required using `.sel` to ensure year is padded
- Add YearProperty descriptor class for automated year padding
- Add property descriptors for all year attributes (start_yr, end_yr, test_start_yr, test_end_yr, ref_start_yr, ref_end_yr)
- Add unit test for automatic year padding functionality
- Uses the pad_year utility function for consistent validation and padding

This enhancement makes year padding automatic and transparent to users, ensuring all year values are properly formatted as 4-digit strings for ISO-8601 compliance and xarray time slicing.
@tomvothecoder tomvothecoder force-pushed the bug/971-iso-8601-dates-enhanced branch from 0dea86e to 36fd6a3 Compare May 9, 2025 19:11
- Logic in `_add_parent_attrs_to_children()` is updated to ignore YearProperty attributes that are not set on the parent object (e.g., CoreParameter). This prevents an AttributeError from being raised
- Update `_add_attrs_with_default_values()` to only add default attribute values to the child parameter if the attributes are set on the parent object
- Update `YearProperty` __get__ to handle when attribute is not set and update __set__ to handle None values
Copy link
Collaborator

@tomvothecoder tomvothecoder left a comment

Choose a reason for hiding this comment

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

This is a clean and thoughtful implementation. Nice work! Unfortunately, it runs into some issues with how e3sm_diags handles parameter objects, specifically with the YearProperty attributes.

The main problem is that these YearProperty attributes show up in dir(parent_param) (list of all attributes) even when they haven’t actually been set. That causes trouble in run.py when we try to pass attributes between parent and child parameter objects. It breaks logic that depends on checking whether an attribute exists or not, because technically it looks like it does, but it really doesn’t.

I added a few workarounds to get the unit tests to pass, but some integration tests are still failing with AttributeError: __delete__ for the YearProperty attributes. I have not found a clear solution for this issue. The current logic for propagating attributes is already pretty complex, and these edge cases make it even harder to get right without adding more complexity to the existing logic.

One simpler alternative could be to just call pad_year on these attributes in CoreParameter.__init__() if they’re explicitly set. It is not as clean as automating this process with YearProperty, but it might be more compatible with the current run.py code. I will explore this route in my PR #972.

@chengzhuzhang
Copy link
Contributor Author

Use solution is #973 instead.

@chengzhuzhang chengzhuzhang deleted the bug/971-iso-8601-dates-enhanced branch May 15, 2025 23:46
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.

[Bug]: Error when running tropical_subseasonal with year value<1000: ValueError: no ISO-8601 or cftime-string-like match for string: 1-01-01

3 participants