NREL-Sienna / InfrastructureSystems.jl

Utility package for Sienna's simulation infrastructure
https://nrel-sienna.github.io/InfrastructureSystems.jl/
BSD 3-Clause "New" or "Revised" License
35 stars 20 forks source link

Fix `compare_values` for arrays with `NaN`, add deserialization for more union types #362

Closed GabrielKS closed 2 months ago

GabrielKS commented 2 months ago

This solves two issues:

  1. Now that PiecewiseStepData HDF-serializes to an array that includes NaN, we need to allow NaN to be equal to itself when checking whether two things are the same — this is accomplished by changing == to isequal.
  2. The new PowerSystems ThermalGenerationCost has a field of type Union{StartUpStages, Float64}, where StartUpStages is a NamedTuple. We didn't have code to deserialize that, but we did have code to deserialize Union{NamedTuple, Nothing}, so I generalized it.

I would have liked to have done most of the logic involved in (2) using the type system, but I did not seem to be able to do so without angering detect_unbound_args. For instance, this method solves the problem (though less generally) but is said to have unbound type parameters:

deserialize(::Type{Union{A, B}}, data::Dict) where {A <: _NOT_FROM_DICT, B <: NamedTuple} = deserialize(B, data)

I'm not sure I believe detect_unbound_args that there are unbound type parameters here, but I have opted for a more manual, less elegant, possibly more flexible approach.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.82%. Comparing base (c723a2b) to head (ce66a4f). Report is 7 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362/graphs/tree.svg?width=650&height=150&src=pr&token=I73yjxYxgn&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna)](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna) ```diff @@ Coverage Diff @@ ## main #362 +/- ## ========================================== + Coverage 75.48% 75.82% +0.34% ========================================== Files 68 68 Lines 4842 4894 +52 ========================================== + Hits 3655 3711 +56 + Misses 1187 1183 -4 ``` | [Flag](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna) | `75.82% <100.00%> (+0.34%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna) | Coverage Δ | | |---|---|---| | [src/hdf5\_time\_series\_storage.jl](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362?src=pr&el=tree&filepath=src%2Fhdf5_time_series_storage.jl&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna#diff-c3JjL2hkZjVfdGltZV9zZXJpZXNfc3RvcmFnZS5qbA==) | `96.70% <100.00%> (ø)` | | | [src/serialization.jl](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362?src=pr&el=tree&filepath=src%2Fserialization.jl&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna#diff-c3JjL3NlcmlhbGl6YXRpb24uamw=) | `74.38% <100.00%> (+4.04%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/NREL-Sienna/InfrastructureSystems.jl/pull/362/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL-Sienna)