Skip to content

Commit 1fa56aa

Browse files
author
Christopher Rowley
committed
Merge remote-tracking branch 'origin/main' into pr/MilesCranmerBot/746
2 parents c46b10b + 9de4d94 commit 1fa56aa

File tree

11 files changed

+85
-38
lines changed

11 files changed

+85
-38
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ updates:
1313
directory: /
1414
schedule:
1515
interval: weekly
16+
- package-ecosystem: julia
17+
directory: /
18+
schedule:
19+
interval: weekly

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Unreleased
44
* Added `juliacall.TypeValue.__numpy_dtype__` attribute to allow converting Julia types
55
to the corresponding NumPy dtype, like `numpy.dtype(jl.Int)`.
6+
* JuliaCall now launches Julia with 1 thread by default.
7+
* Added options `trace_compile` and `trace_compile_timing` to JuliaCall.
8+
* Bug fixes.
69

710
## 0.9.31 (2025-12-17)
811
* Restore support for Python 3.14+.

CondaPkg.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ version = ">=3.10,!=3.14.0,!=3.14.1,<4"
1616
matplotlib = ""
1717
numpy = ""
1818
pyside6 = ""
19+
pandas = ""

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Bringing [**Python®**](https://www.python.org/) and [**Julia**](https://juliala
1414
- Fast non-copying conversion of numeric arrays in either direction: modify Python arrays (e.g. `bytes`, `array.array`, `numpy.ndarray`) from Julia or Julia arrays from Python.
1515
- Helpful wrappers: interpret Python sequences, dictionaries, arrays, dataframes and IO streams as their Julia counterparts, and vice versa.
1616
- Beautiful stack-traces.
17-
- Supports modern systems: tested on Windows, MacOS and Linux, 64-bit, Julia 1.10 upwards and Python 3.10 upwards.
17+
- Supports modern systems: tested on Windows, MacOS and Linux; 64-bit; Julia 1.10 upwards and Python 3.10 upwards.
1818

1919
⭐ If you like this, a GitHub star would be lovely thank you. ⭐
2020

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Bringing [**Python®**](https://www.python.org/) and [**Julia**](https://juliala
77
- Fast non-copying conversion of numeric arrays in either direction: modify Python arrays (e.g. `bytes`, `array.array`, `numpy.ndarray`) from Julia or Julia arrays from Python.
88
- Helpful wrappers: interpret Python sequences, dictionaries, arrays, dataframes and IO streams as their Julia counterparts, and vice versa.
99
- Beautiful stack-traces.
10-
- Works anywhere: tested on Windows, MacOS and Linux, 32- and 64-bit, Julia Julia 1.10 upwards and Python 3.10 upwards.
10+
- Works anywhere: tested on Windows, MacOS and Linux; 64-bit; Julia 1.10 upwards and Python 3.10 upwards.

docs/src/juliacall.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ be configured in two ways:
142142
| `-X juliacall-heap-size-hint=<N>` | `PYTHON_JULIACALL_HEAP_SIZE_HINT=<N>` | Hint for initial heap size in bytes. |
143143
| `-X juliacall-exe=<file>` | `PYTHON_JULIACALL_EXE=<file>` | Path to Julia binary to use (overrides JuliaPkg). |
144144
| `-X juliacall-project=<dir>` | `PYTHON_JULIACALL_PROJECT=<dir>` | Path to the Julia project to use (overrides JuliaPkg). |
145+
| `-X juliacall-trace-compile=<stderr\|name>` | `PYTHON_JULIACALL_TRACE_COMPILE=<stderr\|name>` | Print precompile statements. |
146+
| `-X juliacall-trace-compile-timing` | `PYTHON_JULIACALL_TRACE_COMPILE_TIMING=<yes\|no>` | Include timings with precompile statements. |
145147

146148
## [Multi-threading](@id py-multi-threading)
147149

pysrc/juliacall/__init__.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def init():
6464
"For updates, see https://github.com/pytorch/pytorch/issues/78829."
6565
)
6666

67-
def option(name, default=None, xkey=None, envkey=None):
67+
def option(name, default=None, xkey=None, envkey=None, allowflag=False):
6868
"""Get an option.
6969
7070
Options can be set as command line arguments '-X juliacall-{name}={value}' or as
@@ -73,13 +73,28 @@ def option(name, default=None, xkey=None, envkey=None):
7373
k = xkey or 'juliacall-'+name.lower().replace('_', '-')
7474
v = sys._xoptions.get(k)
7575
if v is not None:
76+
if v is True:
77+
if not allowflag:
78+
raise ValueError(f'-X{k}: expecting an argument')
79+
return True, f'-X{k}'
7680
return v, f'-X{k}={v}'
7781
k = envkey or 'PYTHON_JULIACALL_'+name.upper()
7882
v = os.getenv(k)
7983
if v is not None:
8084
return v, f'{k}={v}'
8185
return default, f'<default>={default}'
8286

87+
def flag(name, default=None, **kw):
88+
v, s = option(name, allowflag=True, **kw)
89+
if v is None:
90+
return default, s
91+
elif v is True or v == 'yes':
92+
return True, s
93+
elif v == 'no':
94+
return False, s
95+
else:
96+
raise ValueError(f'{s}: expecting yes or no')
97+
8398
def choice(name, choices, default=None, **kw):
8499
v, s = option(name, **kw)
85100
if v is None:
@@ -128,7 +143,11 @@ def args_from_config(config):
128143
val = 'no'
129144
else:
130145
continue
131-
argv.append('--' + opt[4:].replace('_', '-') + '=' + val)
146+
arg = '--' + opt[4:].replace('_', '-')
147+
if val is True:
148+
argv.append(arg)
149+
elif val is not None:
150+
argv.append(f"{arg}={val}")
132151
argv = [s.encode("utf-8") for s in argv]
133152

134153
argc = len(argv)
@@ -145,14 +164,16 @@ def args_from_config(config):
145164
CONFIG['opt_home'] = bindir = path_option('home', check_exists=True, envkey='PYTHON_JULIACALL_BINDIR')[0]
146165
CONFIG['opt_check_bounds'] = choice('check_bounds', ['yes', 'no', 'auto'])[0]
147166
CONFIG['opt_compile'] = choice('compile', ['yes', 'no', 'all', 'min'])[0]
167+
CONFIG["opt_trace_compile"] = option('trace_compile')[0]
168+
CONFIG["opt_trace_compile_timing"] = flag('trace_compile_timing')[0]
148169
CONFIG['opt_compiled_modules'] = choice('compiled_modules', ['yes', 'no'])[0]
149170
CONFIG['opt_depwarn'] = choice('depwarn', ['yes', 'no', 'error'])[0]
150171
CONFIG['opt_inline'] = choice('inline', ['yes', 'no'])[0]
151172
CONFIG['opt_min_optlevel'] = choice('min_optlevel', ['0', '1', '2', '3'])[0]
152173
CONFIG['opt_optimize'] = choice('optimize', ['0', '1', '2', '3'])[0]
153174
CONFIG['opt_procs'] = int_option('procs', accept_auto=True)[0]
154175
CONFIG['opt_sysimage'] = sysimg = path_option('sysimage', check_exists=True)[0]
155-
CONFIG['opt_threads'] = int_option('threads', accept_auto=True)[0]
176+
CONFIG['opt_threads'] = option('threads', default='1')[0]
156177
CONFIG['opt_warn_overwrite'] = choice('warn_overwrite', ['yes', 'no'])[0]
157178
CONFIG['opt_handle_signals'] = choice('handle_signals', ['yes', 'no'])[0]
158179
CONFIG['opt_startup_file'] = choice('startup_file', ['yes', 'no'])[0]

src/Wrap/Wrap.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,22 @@ function __init__()
5555
pyconvert_add_rule("collections.abc:Mapping", PyDict, pyconvert_rule_mapping, priority)
5656
pyconvert_add_rule("io:IOBase", PyIO, pyconvert_rule_io, priority)
5757
pyconvert_add_rule("_io:_IOBase", PyIO, pyconvert_rule_io, priority)
58-
pyconvert_add_rule(
59-
"pandas.core.frame:DataFrame",
60-
PyPandasDataFrame,
61-
pyconvert_rule_pandasdataframe,
62-
priority,
63-
)
64-
pyconvert_add_rule(
65-
"pandas.core.arrays.base:ExtensionArray",
66-
PyList,
67-
pyconvert_rule_sequence,
68-
priority,
69-
)
58+
for typename in ["pandas.core.frame:DataFrame", "pandas:DataFrame"]
59+
pyconvert_add_rule(
60+
typename,
61+
PyPandasDataFrame,
62+
pyconvert_rule_pandasdataframe,
63+
priority,
64+
)
65+
end
66+
for typename in ["pandas.core.arrays.base:ExtensionArray", "pandas.api.extensions:ExtensionArray"]
67+
pyconvert_add_rule(
68+
typename,
69+
PyList,
70+
pyconvert_rule_sequence,
71+
priority,
72+
)
73+
end
7074

7175
priority = PYCONVERT_PRIORITY_NORMAL
7276
pyconvert_add_rule("<arraystruct>", Array, pyconvert_rule_array, priority)

test/Compat.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ end
105105
end
106106
end
107107

108-
@testitem "Tables.jl" begin
108+
@testitem "Tables.jl" setup=[Setup] begin
109109
@testset "pytable" begin
110110
x = (x = [1, 2, 3], y = ["a", "b", "c"])
111111
# pandas
112-
# TODO: install pandas and test properly
113-
@test_throws PyException pytable(x, :pandas)
112+
if Setup.devdeps
113+
y = pytable(x, :pandas)
114+
@test pyeq(Bool, pytype(y), pyimport("pandas").DataFrame)
115+
end
114116
# columns
115117
y = pytable(x, :columns)
116118
@test pyeq(Bool, y, pydict(x = [1, 2, 3], y = ["a", "b", "c"]))

test/Convert.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,19 @@ end
305305
@test_throws Exception pyconvert(Second, td(microseconds = 1000))
306306
end
307307

308+
@testitem "pandas.DataFrame → PyPandasDataFrame" setup=[Setup] begin
309+
if Setup.devdeps
310+
pd = pyimport("pandas")
311+
df = pd.DataFrame()
312+
df2 = pyconvert(PyPandasDataFrame, df)
313+
@test df2 isa PyPandasDataFrame
314+
@test pyis(df2, df)
315+
df3 = pyconvert(PyTable, df)
316+
@test df3 isa PyPandasDataFrame
317+
@test pyis(df3, df)
318+
end
319+
end
320+
308321
@testitem "pyconvert_add_rule (#364)" begin
309322
id = string(rand(UInt128), base = 16)
310323
pyexec(

0 commit comments

Comments
 (0)