rafaqz / DimensionalData.jl

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

Add generator syntax as DimArray method #852

Closed kapple19 closed 6 days ago

kapple19 commented 1 week ago

Instead of rebuilding an array comprehension that generates a DimArray to e.g. name it, this allows the cleaner syntax:

julia> DimArray((x, y) for x in X(10:10:50), y in Y(0.0:0.1:1.0); name = :Value)
╭──────────────────────────────────────────────╮
│ 5×11 DimArray{Tuple{Int64, Float64},2} Value │
├──────────────────────────────────────────────┴───────────────────────────────────────────────────────── dims ┐
  ↓ X Sampled{Int64} 10:10:50 ForwardOrdered Regular Points,
  → Y Sampled{Float64} 0.0:0.1:1.0 ForwardOrdered Regular Points
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  ↓ →  0.0         0.1         0.2         0.3         …  0.7         0.8         0.9         1.0
 10     (10, 0.0)   (10, 0.1)   (10, 0.2)   (10, 0.3)      (10, 0.7)   (10, 0.8)   (10, 0.9)   (10, 1.0)        
 20     (20, 0.0)   (20, 0.1)   (20, 0.2)   (20, 0.3)      (20, 0.7)   (20, 0.8)   (20, 0.9)   (20, 1.0)        
 30     (30, 0.0)   (30, 0.1)   (30, 0.2)   (30, 0.3)      (30, 0.7)   (30, 0.8)   (30, 0.9)   (30, 1.0)        
 40     (40, 0.0)   (40, 0.1)   (40, 0.2)   (40, 0.3)      (40, 0.7)   (40, 0.8)   (40, 0.9)   (40, 1.0)        
 50     (50, 0.0)   (50, 0.1)   (50, 0.2)   (50, 0.3)  …   (50, 0.7)   (50, 0.8)   (50, 0.9)   (50, 1.0)

I've added to the documentation that the semi-colon ; is required to distinguish between the generator syntax dimensions and the keyword arguments.

kapple19 commented 1 week ago

Is the nightly error my fault?

asinghvi17 commented 1 week ago

I imagine not, it's failing on my PR as well.

codecov[bot] commented 1 week ago

Codecov Report

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

Project coverage is 84.40%. Comparing base (3dfdcee) to head (c7cb6a8). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #852 +/- ## ========================================== + Coverage 83.38% 84.40% +1.01% ========================================== Files 46 49 +3 Lines 4634 4674 +40 ========================================== + Hits 3864 3945 +81 + Misses 770 729 -41 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.