rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
272 stars 38 forks source link

add setindex and improve merge for stacks #411

Closed rafaqz closed 1 year ago

rafaqz commented 1 year ago

@Lincoln-Hannah this is an example of incremental improvements to the syntax without changing any structure or adding macros.

This lets you merge AbstractDimStack and NamedTuple of AbstractDimArray and get a new AbstrackDimStack back.

# Merge a stack with new layers in another stack or NamedTuple
new_stack = merge(oldstack, (new1=dimarray, new2=dimarrary))
# Or use `NamedTuple` merge
new_stack = DimStack((; oldstack..., new1=dimarray, new2=dimarray))

And for your example in #410 :

Base.setindex(s, 4s[:one], :four)

They are still a bit clunky to use. But these are the kinds of simple Base methods I would hope to build a better syntax on top of. So Base julia NamedTuple methods do all the real work, we just wrap it.

codecov-commenter commented 1 year ago

Codecov Report

Merging #411 (55c0331) into main (266d7e5) will decrease coverage by 4.12%. The diff coverage is 41.17%.

:exclamation: Current head 55c0331 differs from pull request most recent head 1f79d76. Consider uploading reports for the commit 1f79d76 to get more accurate results

@@            Coverage Diff             @@
##             main     #411      +/-   ##
==========================================
- Coverage   90.26%   86.14%   -4.13%     
==========================================
  Files          35       35              
  Lines        2363     2367       +4     
==========================================
- Hits         2133     2039      -94     
- Misses        230      328      +98     
Impacted Files Coverage Δ
src/plotrecipes.jl 0.00% <0.00%> (-81.00%) :arrow_down:
src/stack/stack.jl 93.93% <77.77%> (-2.68%) :arrow_down:
src/LookupArrays/lookup_arrays.jl 81.87% <0.00%> (-0.59%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more