Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson committed Jun 30, 2024
1 parent d3f7728 commit bd933ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/PyArrowTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ Supports:
- the Tables.jl columnar interface, so e.g. `DataFrame(table)` should work. The columns are `PyArray`'s (i.e. `AbstractVector`'s pointing to python objects), or `ChainedVector`'s with `PyArray` subcomponents (if there is more than 1 batch).
- DataAPI's `ncol` and `nrow` accessors.
Currently does not support DataAPI's metadata-related functions, but support may be added later.
Does not yet support:
- DataAPI's metadata-related functions
- `Tables.partitions` to iterate record batches
This functionality may be added in future non-breaking releases.
"""
struct PyArrowTable <: PyTable
py::Py
Expand Down
31 changes: 27 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ using Tables
using DataAPI
using DataFrames
using CondaPkg
using SentinelArrays

const pa = pyarrow

# Print packages for CI logs
CondaPkg.withenv() do
run(`micromamba list`)
return run(`micromamba list`)
end


@testset "PyArrow.jl" begin
jl_table = (; a=[rand(2); NaN], b=["a", "b", "c"])
py_table = PyArrow.table(jl_table)
@test py_table isa Py

t = PyArrowTable(py_table)
# Test indexing

# PythonCall interface
@test PythonCall.ispy(t)
@test pyconvert(Bool, Py(t) == t.py)
@test pyconvert(Bool, Py(t) == py_table)

# Properties
@test isequal(pyconvert(Vector, t["a"]), jl_table.a)
@test isequal(pyconvert(Vector, t[0]), jl_table.a)

# Test property-access
# Test properties
@test propertynames(t) isa Vector{Symbol}
@test :py in propertynames(t)
@test :num_columns in propertynames(t)
@test pyconvert(Int, t.num_columns) == 2
@test pyconvert(Int, t.num_rows) == 3

Expand Down Expand Up @@ -58,6 +69,18 @@ end
jl_table.b[3] = "no"
@test_broken isequal(Tables.getcolumn(t, :a)[3], 5.0)
@test_broken isequal(Tables.getcolumn(t, :b)[3], "no")

# Multiple record batches
data = (; f0 = @py([1, 2, 3, 4]),
f1 = @py(["foo", "bar", "baz", nothing]),
f2 = @py([true, nothing, false, true]))
batch = pa.RecordBatch.from_arrays(pylist(data), @py(["f0", "f1", "f2"]))
table = pa.Table.from_batches(pylist([batch for _ in 1:5]))
@test pyconvert(Bool, table[0].num_chunks == 5)
jl_table = PyArrowTable(table)
@test Tables.getcolumn(jl_table, :f0) isa ChainedVector
@test eltype(Tables.getcolumn(jl_table, :f0)) == Int
@test collect(Tables.getcolumn(jl_table, :f0)) == repeat([1,2,3,4], 5)
end

@testset "README examples" begin
Expand Down

2 comments on commit bd933ea

@ericphanson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110105

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" bd933ea2da6b70ebc611675654efa04f1234f6d3
git push origin v1.0.0

Please sign in to comment.