Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert scalar data to 0-dimensional arrays #36

Merged
merged 13 commits into from
Dec 10, 2022
Merged

Conversation

sethaxen
Copy link
Member

This PR fixes an issue raised by @goedman in StanJulia/StanSample.jl#60 (comment) wherein if one passes an observed_data such as (J=8, y=[1, 2, 3]) to from_namedtuple, one hits a StackOverflow since the method assumes all data in the NamedTuple are arrays.

This PR fixes this by wrapping all non-array data within a NamedTuple with fill to make a 0-dimensional array. It also ensures that these arrays are correctly (de)serialized with netCDF.

Currently tests fail due to rafaqz/DimensionalData.jl#421

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2022

Codecov Report

Merging #36 (54f78b9) into main (84a5aa8) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   95.94%   96.00%   +0.05%     
==========================================
  Files           9        9              
  Lines         296      300       +4     
==========================================
+ Hits          284      288       +4     
  Misses         12       12              
Impacted Files Coverage Δ
src/from_namedtuple.jl 95.12% <ø> (ø)
...ferenceObjectsNetCDF/src/InferenceObjectsNetCDF.jl 95.45% <100.00%> (+0.14%) ⬆️
src/dataset.jl 92.85% <100.00%> (ø)
src/utils.jl 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@sethaxen
Copy link
Member Author

Currently keyword indexing (rafaqz/DimensionalData.jl#423) and the Tables interface (rafaqz/DimensionalData.jl#424) also fail for AbstractDimStacks that contain 0-dimensional arrays, so those would need to work before merging this.

Alternatively, we could take xarray's approach of promoting to a single-element vector and introducing a dummy dimension. There's no real downside to this, and since it just works ™️, perhaps we should adopt that approach instead.

@sethaxen sethaxen closed this Dec 10, 2022
@sethaxen sethaxen reopened this Dec 10, 2022
@sethaxen sethaxen merged commit e011ecb into main Dec 10, 2022
@sethaxen sethaxen deleted the fix_constant_data branch December 10, 2022 14:47
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