Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We should accept any Tables-compatible table as input, instead of only accepting DataFrames #24

Closed
DilumAluthge opened this issue May 7, 2022 · 1 comment · Fixed by #40
Assignees

Comments

@DilumAluthge
Copy link
Member

DilumAluthge commented May 7, 2022

Tables refers to the Tables.jl package.


We should accept any Tables-compatible table as input, instead of only accepting DataFrames.

If the input is already a DataFrame, there's nothing extra we need to do. If the input is not a DataFrame, check if it is a Tables-compatible table. If it isn't a Tables-compatible table, throw an error. If it is a Tables-compatible table, convert it to a DataFrame.

Here is some example code.

using DataFrames: DataFrame
import Tables

function my_cool_function(df::DataFrame)
    # do stuff
end

function my_cool_function(input_object)
    assert_is_table(input_object)

    # convert `input_object` to a `DataFrame`
    df = DataFrame(input_object)::DataFrame

    # Assert that `df` is in fact a `DataFrame`
    df::DataFrame

    return my_cool_function(df)
end

function assert_is_table(x)
    if !Tables.istable(x)
        msg = "Input must be a table, but $(typeof(x)) is not a table"
        throw(ArgumentError(msg))
    end
    return nothing
end
@AshlinHarris
Copy link
Contributor

#40

@AshlinHarris AshlinHarris linked a pull request May 17, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants