Skip to content

Fix vanilla_yaml to process regular dicts containing datetime objects#65

Merged
DavidHuber-NOAA merged 3 commits intodevelopfrom
copilot/fix-vanilla-yaml-call
Jan 8, 2026
Merged

Fix vanilla_yaml to process regular dicts containing datetime objects#65
DavidHuber-NOAA merged 3 commits intodevelopfrom
copilot/fix-vanilla-yaml-call

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Description

The vanilla_yaml function only recursively processed AttrDict instances, leaving datetime objects (and other special types) unprocessed in regular Python dictionaries. This caused YAML serialization to fail when regular dicts containing datetime objects appeared in the data structure.

Changes

  • Modified isinstance(ctx, AttrDict) check to isinstance(ctx, dict) in vanilla_yaml function
  • Since AttrDict inherits from dict, existing behavior is preserved while extending support to regular dictionaries
  • Added test coverage for regular dicts, nested structures, and mixed AttrDict/dict scenarios
  • Fixed code style issues (import ordering and trailing whitespace) to pass pynorms checks

Example

from datetime import datetime
from wxflow.yaml_file import vanilla_yaml

# Before: datetime not converted in regular dict
data = {'key': datetime(2024, 1, 1, 12, 0, 0)}
vanilla_yaml(data)  # Returns: {'key': datetime.datetime(2024, 1, 1, 12, 0)}

# After: datetime properly converted
vanilla_yaml(data)  # Returns: {'key': '2024-01-01T12:00:00Z'}

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • pynorms
  • pytests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes need updates to the documentation. I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • New and existing tests pass with my changes
  • Any dependent changes have been merged and published
Original prompt

This section details on the original issue you should resolve

<issue_title>Vanilla YAML should also be called for regular dictionaries</issue_title>
<issue_description>

if isinstance(ctx, AttrDict):
return {kk: vanilla_yaml(vv) for kk, vv in ctx.items()}

The above will loop through keys for an AttrDict and run Vanilla_yaml, but this should also be done if the item is a regular dictionary (as it may contain items that need to be cleaned)</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.39%. Comparing base (de88f84) to head (dc1e668).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #65      +/-   ##
===========================================
+ Coverage    60.24%   60.39%   +0.15%     
===========================================
  Files           24       24              
  Lines         1972     1972              
  Branches       370      307      -63     
===========================================
+ Hits          1188     1191       +3     
+ Misses         727      726       -1     
+ Partials        57       55       -2     

☔ 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.

Copilot AI changed the title [WIP] Fix Vanilla YAML processing for regular dictionaries Fix vanilla_yaml to process regular dicts containing datetime objects Jan 8, 2026
Copilot AI requested a review from CoryMartin-NOAA January 8, 2026 20:58
@CoryMartin-NOAA
Copy link
Collaborator

@copilot please fix the pynorms test that is failing

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot please fix the pynorms test that is failing

Fixed in dc1e668. The pynorms test was failing due to:

  1. Incorrect import order (imports should be alphabetically sorted)
  2. Trailing whitespace on blank lines

Both issues have been resolved.

Copy link
Contributor

@DavidHuber-NOAA DavidHuber-NOAA left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for this additional functionality @CoryMartin-NOAA!

@DavidHuber-NOAA
Copy link
Contributor

Let us know when you are satisfied with your testing and mark it Ready for Review.

@CoryMartin-NOAA CoryMartin-NOAA marked this pull request as ready for review January 8, 2026 21:26
@CoryMartin-NOAA
Copy link
Collaborator

Thanks @DavidHuber-NOAA. I love when I am debugging something for like 5 hours and it's a simple fix! haha

@DavidHuber-NOAA DavidHuber-NOAA merged commit 88c576d into develop Jan 8, 2026
17 checks passed
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.

Vanilla YAML should also be called for regular dictionaries

3 participants