|
|
|
|
|
by refactor_master
455 days ago
|
|
It seems like this hack would be fine for notebooks, but not something I’d be interested in for production code. Why not just something like this? def f(n):
time.sleep(random.uniform(0.1, 0.3)) # Simulate network delay
return pd.DataFrame({"A": [n, n+1], "B": [n*2, (n+1)*2]})
with ThreadPoolExecutor() as ex:
df = pd.concat(ex.map(f, range(3)), ignore_index=True)
|
|
That said, this is mostly just going to be helpful if you're running pandas operations that call an external API on each iteration or something, and the actual pandas part of the work is still going to be CPU-bound and block. I am also not a huge fan of the monkey-patching approach. But it's clever and will definitely be useful to folks doing a very specific kind of work