Skip to content

Define methods Tables.columnaccess and Tables.rowaccess #70

@ronisbr

Description

@ronisbr

Hi!

Recently, a user of my package PrettyTables.jl found an issue (ronisbr/PrettyTables.jl#51) when trying to print a DataFrame from Pandas. It turns out that, although Pandas.DataFrame provide full support for Tables.jl API (both row and column access), the methods Tables.rowaccess and Tables.columnaccess return false. Hence, PrettyTables.jl does not know how to get the data.

My suggestion is to define the following two methods:

Tables.columnaccess(::Pandas.DataFrame) = true
Tables.rowaccess(::Pandas.DataFrame) = true

which will tell to the packages that Pandas.DataFrame has the capability to access data by rows and columns. In this case, we can do:

julia> using PrettyTables

julia> using Tables

julia> using Pandas

julia> df = DataFrame(Dict(:age=>[27, 29, 27], :name=>["James", "Jill", "Jake"]));

julia> Tables.columnaccess(::Pandas.DataFrame) = true

julia> pretty_table(df)
┌─────┬───────┐
│ age │  name │
├─────┼───────┤
│  27 │ James │
│  29 │  Jill │
│  27 │  Jake │
└─────┴───────┘

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