Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
* Added `juliacall.TypeValue.__numpy_dtype__` attribute to allow converting Julia types
to the corresponding NumPy dtype, like `numpy.dtype(jl.Int)`.
* Bug fixes.

## 0.9.31 (2025-12-17)
* Restore support for Python 3.14+.
Expand Down
1 change: 1 addition & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ version = ">=3.10,!=3.14.0,!=3.14.1,<4"
matplotlib = ""
numpy = ""
pyside6 = ""
pandas = ""
28 changes: 16 additions & 12 deletions src/Wrap/Wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ function __init__()
pyconvert_add_rule("collections.abc:Mapping", PyDict, pyconvert_rule_mapping, priority)
pyconvert_add_rule("io:IOBase", PyIO, pyconvert_rule_io, priority)
pyconvert_add_rule("_io:_IOBase", PyIO, pyconvert_rule_io, priority)
pyconvert_add_rule(
"pandas.core.frame:DataFrame",
PyPandasDataFrame,
pyconvert_rule_pandasdataframe,
priority,
)
pyconvert_add_rule(
"pandas.core.arrays.base:ExtensionArray",
PyList,
pyconvert_rule_sequence,
priority,
)
for typename in ["pandas.core.frame:DataFrame", "pandas:DataFrame"]
pyconvert_add_rule(
typename,
PyPandasDataFrame,
pyconvert_rule_pandasdataframe,
priority,
)
end
for typename in ["pandas.core.arrays.base:ExtensionArray", "pandas.api.extensions:ExtensionArray"]
pyconvert_add_rule(
typename,
PyList,
pyconvert_rule_sequence,
priority,
)
end

priority = PYCONVERT_PRIORITY_NORMAL
pyconvert_add_rule("<arraystruct>", Array, pyconvert_rule_array, priority)
Expand Down
8 changes: 5 additions & 3 deletions test/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ end
end
end

@testitem "Tables.jl" begin
@testitem "Tables.jl" setup=[Setup] begin
@testset "pytable" begin
x = (x = [1, 2, 3], y = ["a", "b", "c"])
# pandas
# TODO: install pandas and test properly
@test_throws PyException pytable(x, :pandas)
if Setup.devdeps
y = pytable(x, :pandas)
@test pyeq(Bool, pytype(y), pyimport("pandas").DataFrame)
end
# columns
y = pytable(x, :columns)
@test pyeq(Bool, y, pydict(x = [1, 2, 3], y = ["a", "b", "c"]))
Expand Down
13 changes: 13 additions & 0 deletions test/Convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ end
@test_throws Exception pyconvert(Second, td(microseconds = 1000))
end

@testitem "pandas.DataFrame → PyPandasDataFrame" setup=[Setup] begin
if Setup.devdeps
pd = pyimport("pandas")
df = pd.DataFrame()
df2 = pyconvert(PyPandasDataFrame, df)
@test df2 isa PyPandasDataFrame
@test pyis(df2, df)
df3 = pyconvert(PyTable, df)
@test df3 isa PyPandasDataFrame
@test pyis(df3, df)
end
end

@testitem "pyconvert_add_rule (#364)" begin
id = string(rand(UInt128), base = 16)
pyexec(
Expand Down
33 changes: 15 additions & 18 deletions test/Wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,26 +458,23 @@ end
end
end

@testitem "PyPandasDataFrame" begin
@testitem "PyPandasDataFrame" setup=[Setup] begin
using Tables
@test PyPandasDataFrame isa Type
# TODO: figure out how to get pandas into the test environment
# for now use some dummy type and take advantage of the fact that the code doesn't actually check it's a real dataframe
@pyexec """
class DataFrame:
def __init__(self, **kw):
self.__dict__.update(kw)
""" => DataFrame
df = DataFrame(shape = (4, 3), columns = pylist(["foo", "bar", "baz"]))
x = PyPandasDataFrame(df)
@test ispy(x)
@test Py(x) === df
@test Tables.istable(x)
@test Tables.columnaccess(x)
@test_throws Exception Tables.columns(x)
@test_throws Exception pyconvert(PyPandasDataFrame, 1)
str = sprint(show, MIME("text/plain"), x)
@test occursin(r"4×3 .*PyPandasDataFrame", str)
if Setup.devdeps
pd = pyimport("pandas")
df = pd.DataFrame(pydict(foo=pylist([1,2,3,4]), bar=pylist([2,3,4,5]), baz=pylist([3,4,5,6])))
x = PyPandasDataFrame(df)
@test ispy(x)
@test Py(x) === df
@test Tables.istable(x)
@test Tables.columnaccess(x)
# TODO: test the tables interface more fully
Tables.columns(x)
@test_throws Exception pyconvert(PyPandasDataFrame, 1)
str = sprint(show, MIME("text/plain"), x)
@test occursin(r"4×3 .*PyPandasDataFrame", str)
end
end

@testitem "PySet" begin
Expand Down
Loading