Skip to content

Commit 269f7ae

Browse files
fix: warnings for pyodide
1 parent 5af65e6 commit 269f7ae

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

meson.build

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ py = import('python').find_installation(pure: false)
1515
tempita = files('generate_pxi.py')
1616
versioneer = files('generate_version.py')
1717

18-
# Find OpenMP dependency
18+
# Find OpenMP dependency - skip for Pyodide/WebAssembly builds
19+
is_pyodide_build = false
20+
cc = meson.get_compiler('c')
21+
22+
# Check if we're building for WebAssembly/Pyodide
23+
if cc.get_id() == 'clang' and host_machine.cpu_family() == 'wasm32'
24+
is_pyodide_build = true
25+
message('Detected Pyodide/WebAssembly build - skipping OpenMP')
26+
endif
27+
1928
openmp_dep = dependency('openmp', required: false)
20-
if not openmp_dep.found()
29+
if not openmp_dep.found() and not is_pyodide_build
2130
# Try to find OpenMP using compiler flags
22-
cc = meson.get_compiler('c')
2331
if cc.has_argument('-fopenmp')
2432
openmp_dep = declare_dependency(
2533
compile_args: ['-fopenmp'],
@@ -40,13 +48,17 @@ add_project_arguments(
4048
language: 'cpp',
4149
)
4250

43-
# Add OpenMP compile args if available
44-
if openmp_dep.found()
51+
# Add OpenMP compile args if available and not building for Pyodide
52+
if openmp_dep.found() and not is_pyodide_build
4553
add_project_arguments('-DHAVE_OPENMP', language: 'c')
4654
add_project_arguments('-DHAVE_OPENMP', language: 'cpp')
4755
message('OpenMP support enabled')
4856
else
49-
message('OpenMP not found - parallel code will run sequentially')
57+
if is_pyodide_build
58+
message('OpenMP disabled for Pyodide/WebAssembly build')
59+
else
60+
message('OpenMP not found - parallel code will run sequentially')
61+
endif
5062
endif
5163

5264
if fs.exists('_version_meson.py')

pandas/_libs/algos.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ from libc.stdlib cimport (
1111
)
1212
from libc.string cimport memmove
1313

14+
import sys
15+
1416
import numpy as np
1517

1618
cimport numpy as cnp
@@ -365,6 +367,10 @@ def nancorr(
365367
float64_t mean, ssqd, val
366368
float64_t vx, vy, dx, dy, meanx, meany, divisor, ssqdmx, ssqdmy, covxy, corr_val
367369

370+
# Disable parallel execution in Pyodide/WebAssembly environment
371+
if use_parallel and hasattr(sys, "platform") and sys.platform == "emscripten":
372+
use_parallel = False
373+
368374
N, K = (<object>mat).shape
369375
if minp is None:
370376
minpv = 1

pandas/core/frame.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11374,7 +11374,19 @@ def corr(
1137411374
mat = data.to_numpy(dtype=float, na_value=np.nan, copy=False)
1137511375

1137611376
if method == "pearson":
11377-
correl = libalgos.nancorr(mat, minp=min_periods, use_parallel=use_parallel)
11377+
if use_parallel:
11378+
try:
11379+
correl = libalgos.nancorr(mat, minp=min_periods, use_parallel=True)
11380+
except (ImportError, AttributeError, RuntimeError):
11381+
# OpenMP not available or prange failed, fall back to sequential
11382+
warnings.warn(
11383+
"No parallelism; using sequential (e.g. Pyodide or no OpenMP).",
11384+
UserWarning,
11385+
stacklevel=find_stack_level(),
11386+
)
11387+
correl = libalgos.nancorr(mat, minp=min_periods, use_parallel=False)
11388+
else:
11389+
correl = libalgos.nancorr(mat, minp=min_periods, use_parallel=False)
1137811390
elif method == "spearman":
1137911391
correl = libalgos.nancorr_spearman(mat, minp=min_periods)
1138011392
elif method == "kendall" or callable(method):

0 commit comments

Comments
 (0)