'C-Stack usage is too close to limit - not due to recursive code
I have an intruiging question, and I can not seem to find the answer. I have a specific python function, which runs a sql script, gets the data and transforms it into a pd.DataFrame. The size of a typical response is around 100Kb (83.9Kb in the example below):
When I run the exact same function, which I import in an R session using reticulate
, I get a "C Stack usage too close to the limit error".
I do not understand why R gives me such a response for such a small dataframe. Does it have to do with the translation of Python code to R via reticulate? Quite a specific question, but I am curious to know if somebody knows the answer
Please see the code of the Python function below:
def get_raw_data_(make, year):
sql_file = WORKING_DIRECTORY.joinpath("sql/get_raw_data.sql")
sql_string = sql_script_to_string(sql_file)
dragend_rules_file = WORKING_DIRECTORY.joinpath(f'sql/dragend_rules/{make}.sql')
dragend_rules = sql_script_to_string(dragend_rules_file)
tellend_rules_file = WORKING_DIRECTORY.joinpath(f'sql/tellend_rules/{make}.sql')
tellend_rules = sql_script_to_string(tellend_rules_file)
to_replace = {
'INSERT_YEAR':year,
'INSERT_DRAGEND_RULES':dragend_rules,
'INSERT_TELLEND_RULES':tellend_rules
}
for key, value in to_replace.items():
sql_string = sql_string.replace(key,value)
sql_string = sql_string.replace('INSERT_MAKE', make)
res = execute_sql(sql_string, cur)
res = pd.DataFrame(res, columns = [
"CONTRACTNR", "MAKE", "TYPE",
"VEHICLEKIND", "STATUS", "LICENSEPLATE",
"FUELTYPE", "COMMERCIALUNITLEVEL1", "YEARMONTHREGISTRATION",
"DRAGEND"
])
res = res.reset_index(drop=True)
cols_fact = res.columns[~res.columns.isin(['CONTRACTNR', 'YEARMONTHREGISTRATION'])]
res[cols_fact] = res[cols_fact].astype('category')
return res
I call this function in R as follows:
source('get_raw_data.py')
get_raw_data_('ME', '2021')
Solution 1:[1]
I had the same problem, but querying GCP Firestore documents.
After so many hours looking for documentation and trying different options, I managed to solve it (still not sure what was causing the problem) using "reticulate dev version" as said in https://github.com/rstudio/reticulate/issues/885.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | maalidvacc |