You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In "Part 2 Instructions (Exercises)," when modifying and running a part of extract_historical_weather_data.py as specified in Exercise 2, the above error occurs.
When you run type(historical_weather) to check the type of the variable historical_weather, it outputs the following:
<class 'airflow.models.xcom.LazyXComAccess'>
This means that the code is entering the else part of the if type(historical_weather) == list : statement in the turn_json_into_table function, which is causing this issue.
defturn_json_into_table(
duckdb_conn_id: str,
historical_weather_table_name: str,
historical_weather: dict,
):
""" Convert the JSON input with info about historical weather into a pandas DataFrame and load it into DuckDB. Args: duckdb_conn_id (str): The connection ID for the DuckDB connection. historical_weather_table_name (str): The name of the table to store the historical weather data. historical_weather (list): The historical weather data to load into DuckDB. """fromduckdb_provider.hooks.duckdb_hookimportDuckDBHookiftype(historical_weather) ==list:
list_of_df= []
foriteminhistorical_weather:
df=pd.DataFrame(item)
list_of_df.append(df)
historical_weather_df=pd.concat(list_of_df, ignore_index=True)
else:
historical_weather_df=pd.DataFrame(historical_weather)
Proposed Solution:
By commenting out the entire block of the above if statement and modifying the code to run the following part directly, it worked successfully. If you have any better suggestions for a fix, please let me know.
How to reproduce:
In "Part 2 Instructions (Exercises)," when modifying and running a part of extract_historical_weather_data.py as specified in Exercise 2, the above error occurs.
Cause:
When you run type(historical_weather) to check the type of the variable historical_weather, it outputs the following:
<class 'airflow.models.xcom.LazyXComAccess'>
This means that the code is entering the else part of the
if type(historical_weather) == list
: statement in the turn_json_into_table function, which is causing this issue.Proposed Solution:
By commenting out the entire block of the above if statement and modifying the code to run the following part directly, it worked successfully. If you have any better suggestions for a fix, please let me know.
The text was updated successfully, but these errors were encountered: