Skip to content

Add defaultarray function to figure out optimal array type based on the element type #31601

Open

Description

When collecting an iterable into a column based table, it is not obvious what array type to use for the various elements. For example CategoricalValue from CategoricalArrays should clearly be collected in a CategoricalArray that is optimized for that type, WeakRefString from WeakRefStrings belongs in a StringArray (which is optimized to store those), DataValue naturally belongs to a DataValueArray etc.

This makes it very hard to write code that would collect an iterable into its "optimized container" without depending on all the above packages (or using Requires like here), which in my view is a design that does not scale. I feel that this could be solved by adding a defaultarray(T, sz) = Array{T}(undef, sz) function in Base that the various packages (CategoricalArrays, WeakRefStrings, DataValueArrays) could then overload. In this way one could write a collect optimized for the element type without any dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions