Skip to content

Enhance functionality of RefTuple labels #425

Closed
@jmh530

Description

@jmh530

It occurs to me that a slices label[] can fit a slice of RefTuples. So for instance, I can fit dates and really anything else. This is a big win for working with dataframes since it would enable you to create a heterogeneous array where the main data is numerical or some kind but has a more sophisticated set of labels.

However, it seems that there are still some limitations in working with these. So for instance the code below struggles with just reading out the values from them. It doesn't apply in the same way to the original zipped values, suggesting that it is when coercing it to be a label[] that causes the issue.

void main() {
    import mir.ndslice.slice;
    import mir.ndslice.allocation: slice;
    import mir.date: Date;
    import mir.functional: RefTuple, refTuple;
    import mir.ndslice.topology: map, zip, unzip;
    import std.stdio: writeln;

    auto dataframe = slice!(double, RefTuple!(Date, string), string)(4, 3);

    auto dataframe_dates = [Date(2019, 1, 24),
                            Date(2019, 2, 2),
                            Date(2019, 2, 4),
                            Date(2019, 2, 5)
    ];
    
    auto dataframe_colors = ["red", "blue", "red", "blue"];
    auto combined = zip(dataframe_dates, dataframe_colors);
    
    // Fill row labels
    dataframe.label[] = combined;

    // Fill column labels
    dataframe.label!1[] = ["income", "outcome", "balance"];

    writeln(combined.unzip!'a');
    //writeln(dataframe.label!0.unzip!'a'); // error
    writeln(dataframe.label!0[1][0]);
    //writeln(dataframe.label!0.map!(a => a[0])); // error
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions