Skip to content
Open
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: 0 additions & 1 deletion .github/workflows/tests-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
JULIA_DEBUG: PythonCall
JULIA_NUM_THREADS: '2'
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v5
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ jobs:
- name: Run tests
uses: julia-actions/julia-runtest@v1
env:
JULIA_DEBUG: PythonCall
JULIA_NUM_THREADS: '2'
PYTHON: python
JULIA_PYTHONCALL_EXE: ${{ matrix.pythonexe }}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* The vast majority of these changes are breaking, see the [v1 Migration Guide](@ref) for how to upgrade.
* Changes to core functionality:
* Comparisons like `==(::Py, ::Py)`, `<(::Py, ::Number)`, `isless(::Number, ::Py)` now return `Bool` instead of `Py`.
* Changes to conversion:
* `pyconvert` rules are now scoped by target type instead of prioritized; rules are ordered by Python type specificity and creation order.
* `pyconvert_add_rule` now has the signature `pyconvert_add_rule(func::Function, t::String, ::Type{T}, ::Type{S}=T)`; the optional scope `S` controls when a rule is considered during conversion.
* Changes to `PythonCall.GC` (now more like `Base.GC`):
* `enable(true)` replaces `enable()`.
* `enable(false)` replaces `disable()`.
Expand Down
1 change: 1 addition & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ version = ">=3.10,<3.14"
[dev.deps]
matplotlib = ""
numpy = ""
pandas = ""
pyside6 = ""
python = "<3.14"
115 changes: 64 additions & 51 deletions docs/src/conversion-to-julia.md

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/API/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ export pyxor
export @pyconvert
export pyconvert
export pyconvert_add_rule
export PYCONVERT_PRIORITY_ARRAY
export PYCONVERT_PRIORITY_CANONICAL
export PYCONVERT_PRIORITY_FALLBACK
export PYCONVERT_PRIORITY_NORMAL
export PYCONVERT_PRIORITY_WRAP
export pyconvert_return
export pyconvert_unconverted

Expand Down
10 changes: 0 additions & 10 deletions src/API/types.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# Convert

@enum PyConvertPriority begin
PYCONVERT_PRIORITY_WRAP = 400
PYCONVERT_PRIORITY_ARRAY = 300
PYCONVERT_PRIORITY_CANONICAL = 200
PYCONVERT_PRIORITY_NORMAL = 0
PYCONVERT_PRIORITY_FALLBACK = -100
end

# Core

"""
Expand Down
8 changes: 2 additions & 6 deletions src/Convert/Convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import ..PythonCall:
pyconvert_add_rule,
pyconvert_return,
pyconvert_unconverted,
pyconvert,
PyConvertPriority
pyconvert

export pyconvert_isunconverted,
pyconvert_result,
Expand All @@ -36,10 +35,7 @@ include("numpy.jl")
include("pandas.jl")

function __init__()
init_pyconvert()
init_ctypes()
init_numpy()
init_pandas()
init_pyconvert_extratypes()
end

end
28 changes: 0 additions & 28 deletions src/Convert/ctypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,3 @@ const CTYPES_SIMPLE_TYPES = [
("void_p", Ptr{Cvoid}),
]

function init_ctypes()
for (t, T) in CTYPES_SIMPLE_TYPES
isptr = endswith(t, "_p")
isreal = !isptr
isnumber = isreal
isfloat = t in ("float", "double")
isint = isreal && !isfloat
isuint = isint && (startswith(t, "u") || t == "size_t")

name = "ctypes:c_$t"
rule = pyconvert_rule_ctypessimplevalue{T,false}()
saferule = pyconvert_rule_ctypessimplevalue{T,true}()

t == "char_p" && pyconvert_add_rule(name, Cstring, saferule)
t == "wchar_p" && pyconvert_add_rule(name, Cwstring, saferule)
pyconvert_add_rule(name, T, saferule)
isuint && pyconvert_add_rule(name, UInt, sizeof(T) ≤ sizeof(UInt) ? saferule : rule)
isuint && pyconvert_add_rule(name, Int, sizeof(T) < sizeof(Int) ? saferule : rule)
isint &&
!isuint &&
pyconvert_add_rule(name, Int, sizeof(T) ≤ sizeof(Int) ? saferule : rule)
isint && pyconvert_add_rule(name, Integer, rule)
isfloat && pyconvert_add_rule(name, Float64, saferule)
isreal && pyconvert_add_rule(name, Real, rule)
isnumber && pyconvert_add_rule(name, Number, rule)
isptr && pyconvert_add_rule(name, Ptr, saferule)
end
end
61 changes: 0 additions & 61 deletions src/Convert/numpy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,64 +97,3 @@ const NUMPY_SIMPLE_TYPES = [
("complex128", ComplexF64),
]

function init_numpy()
# simple numeric scalar types
for (t, T) in NUMPY_SIMPLE_TYPES
isbool = occursin("bool", t)
isint = occursin("int", t) || isbool
isuint = occursin("uint", t) || isbool
isfloat = occursin("float", t)
iscomplex = occursin("complex", t)
isreal = isint || isfloat
isnumber = isreal || iscomplex

name = "numpy:$t"
rule = pyconvert_rule_numpysimplevalue{T,false}()
saferule = pyconvert_rule_numpysimplevalue{T,true}()

pyconvert_add_rule(name, T, saferule, PYCONVERT_PRIORITY_ARRAY)
isuint && pyconvert_add_rule(name, UInt, sizeof(T) ≤ sizeof(UInt) ? saferule : rule)
isuint && pyconvert_add_rule(name, Int, sizeof(T) < sizeof(Int) ? saferule : rule)
isint &&
!isuint &&
pyconvert_add_rule(name, Int, sizeof(T) ≤ sizeof(Int) ? saferule : rule)
isint && pyconvert_add_rule(name, Integer, rule)
isfloat && pyconvert_add_rule(name, Float64, saferule)
isreal && pyconvert_add_rule(name, Real, rule)
iscomplex && pyconvert_add_rule(name, ComplexF64, saferule)
iscomplex && pyconvert_add_rule(name, Complex, rule)
isnumber && pyconvert_add_rule(name, Number, rule)
end

# datetime64
pyconvert_add_rule(
"numpy:datetime64",
DateTime64,
pyconvert_rule_datetime64,
PYCONVERT_PRIORITY_ARRAY,
)
pyconvert_add_rule("numpy:datetime64", InlineDateTime64, pyconvert_rule_datetime64)
pyconvert_add_rule(
"numpy:datetime64",
NumpyDates.DatesInstant,
pyconvert_rule_datetime64,
)
pyconvert_add_rule("numpy:datetime64", Missing, pyconvert_rule_datetime64)
pyconvert_add_rule("numpy:datetime64", Nothing, pyconvert_rule_datetime64)

# timedelta64
pyconvert_add_rule(
"numpy:timedelta64",
TimeDelta64,
pyconvert_rule_timedelta64,
PYCONVERT_PRIORITY_ARRAY,
)
pyconvert_add_rule("numpy:timedelta64", InlineTimeDelta64, pyconvert_rule_timedelta64)
pyconvert_add_rule(
"numpy:timedelta64",
NumpyDates.DatesPeriod,
pyconvert_rule_timedelta64,
)
pyconvert_add_rule("numpy:timedelta64", Missing, pyconvert_rule_timedelta64)
pyconvert_add_rule("numpy:timedelta64", Nothing, pyconvert_rule_timedelta64)
end
9 changes: 0 additions & 9 deletions src/Convert/pandas.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
pyconvert_rule_pandas_na(::Type{Nothing}, x::Py) = pyconvert_return(nothing)
pyconvert_rule_pandas_na(::Type{Missing}, x::Py) = pyconvert_return(missing)

function init_pandas()
pyconvert_add_rule(
"pandas._libs.missing:NAType",
Missing,
pyconvert_rule_pandas_na,
PYCONVERT_PRIORITY_CANONICAL,
)
pyconvert_add_rule("pandas._libs.missing:NAType", Nothing, pyconvert_rule_pandas_na)
end
Loading
Loading