Skip to content

feat/bug: the median of the values in the array #11788

@raisadz

Description

@raisadz

Is your feature request related to a problem?

Could you please consider implementing the median function of the values in the array similar to the mean function https://ibis-project.org/reference/expression-collections#ibis.expr.types.arrays.ArrayValue.means

import ibis
   ...: >>> ibis.options.interactive = True
   ...: >>> t = ibis.memtable({"arr": [[1, 2, 3], [None, 6], [None], [], None]})
   ...: >>> t.mutate(x=t.arr.medians())

AttributeError: 'ArrayColumn' object has no attribute 'medians'

It also looks like if I try arr.median() it outputs the following which doesn't look right:

import ibis
   ...: >>> ibis.options.interactive = True
   ...: >>> t = ibis.memtable({"arr": [[1, 2, 3], [None, 6], [None], [], None]})
   ...: >>> t.mutate(x=t.arr.median())
Out[1]: 
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ arr                  ┃ x                    ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64>         │ array<int64>         │
├──────────────────────┼──────────────────────┤
│ [1, 2, ... +1]       │ [1, 2, ... +1]       │
│ [None, 6]            │ [1, 2, ... +1]       │
│ [None]               │ [1, 2, ... +1]       │
│ []                   │ [1, 2, ... +1]       │
│ NULL                 │ [1, 2, ... +1]       │
└──────────────────────┴──────────────────────┘

What is the motivation behind your request?

Describe the solution you'd like

import ibis
   ...: >>> ibis.options.interactive = True
   ...: >>> t = ibis.memtable({"arr": [[1, 2, 3], [None, 6], [None], [], None]})
   ...: >>> t.mutate(x=t.arr.medians())

┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ arr                  ┃ x       ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ array<int64>         │ float64 │
├──────────────────────┼─────────┤
│ [1, 2, ... +1]       │     2.0 │
│ [None, 6]            │     6.0 │
│ [None]               │    NULL │
│ []                   │    NULL │
│ NULL                 │    NULL │
└──────────────────────┴─────────┘

What version of ibis are you running?

11.0.0

What backend(s) are you using, if any?

DuckDB

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeatures or general enhancements

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions