mcabbott / mcabbott/AxisKeys.jl

Support for NaNStatistics

Open
#147 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
154
Forks
31
PR merge metrics
No merged PRs in 30d

Description

It would be very handy if there was support for NaNStatistics. I couldn't find an easy way to rewrap the output array so I did this ugly workaround:

NaNStatistics.nansum(A::KeyedArray; dim=:, dims=:) = rewrap_keyedarray(nansum(A.data.data; dim, dims), A, dims isa Colon ? dim : dims)

function rewrap_keyedarray(new, original, dims)
    axs = NamedTuple{propertynames(original)}(original.keys) |> pairs
    if ndims(new) < ndims(original)
        axs = collect(axs)[1:end .!= dims]
    else
        axs = Dict(axs)
        for dim in dims
            axs[propertynames(original)[dim]] = axes(new, dim)
        end
        axs = [k => axs[k] for k in propertynames(original)]
    end
    KeyedArray(new; axs...)
end

Thanks

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the NaNStatistics.nansum example from the issue and inspect how AxisKeys currently wraps array operations and preserves KeyedArray axes. Done means NaNStatistics operations work on KeyedArray inputs with the expected keys and dimensions, without requiring the shown rewrap_keyedarray workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.