Apr-12-2024, 09:32 PM
So have a script called backtest.pyx. Script works fine with no errors/warnings.
Now I compliled the entire script using cython and I have the pyd file backtest.cp312-win_amd64.pyd
Next I have a script called test.py where the code in there is just:
When the compiled version of the script runs, I get a bunch of warnings:
Now I suppose I could just try and silence those warnings. But I'd rather fix the core issue. I do need to do something because I need to run my script in parallel using joblib - right now the cython compiled version just gets hung when I'm using the joblib code, I'm guessing that may be because of the warnings thrown. All of the above examples was me using a for loop to run a function in series instead of using joblib to run in parallel.
What is the solution?
Now I compliled the entire script using cython and I have the pyd file backtest.cp312-win_amd64.pyd
Next I have a script called test.py where the code in there is just:
import backtestSo I run test.py, and the cython compiled version of my script runs. FYI I did not make any cython specific optimizations to my backtest.pyx script, I'm just compiling the script as-is for nowsince this is the start of my cython journey.
When the compiled version of the script runs, I get a bunch of warnings:
Error:C:\Users\thpfs\documents\python\cython\test.py:1: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!
You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.
A typical example is when you are setting values in a column of a DataFrame, like:
df["col"][row_indexer] = value
Use `df.loc[row_indexer, "col"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
So I want to fix the chained assignments, so in my original, uncompiled script backtest.pyx I addpd.set_option('mode.chained_assignment', 'raise')This script still runs fine, no warnings/errors raised. I've scanned my code, I can't find any chained assingments. But cython compiled still throws warnings for chained assignments...
Now I suppose I could just try and silence those warnings. But I'd rather fix the core issue. I do need to do something because I need to run my script in parallel using joblib - right now the cython compiled version just gets hung when I'm using the joblib code, I'm guessing that may be because of the warnings thrown. All of the above examples was me using a for loop to run a function in series instead of using joblib to run in parallel.
What is the solution?