I execute the code def read_data(**kwargs): import logging import pandas as pd import…
- User
I execute the code def read_data(**kwargs):
codeimport logging import pandas as pd import numpy as np import common as cm ti = kwargs['ti'] start_timestamp = cm._utc_to_msk(kwargs['data_interval_start']) end_timestamp = cm._utc_to_msk(kwargs['data_interval_end']) query = f"""SELECT "ym_id" as "ClientId", 'success_event_7777' as "Target", extract(epoch from "Дата события"::date) as "DateTime" FROM base.csv_all_events cae where main_product_id = '800' and "Номер события" = 7777 and ym_id <> 'Не указано' and "Дата события"::date >= '{start_timestamp}'::date and "Дата события"::date < '{end_timestamp}'::date """ df = cm._read_from_db(query) df.to_csv('metrika_temp_7777.csv', index=False) logging.info(f'Writing {df.size} rows') return(df.size) and getting error ERROR - Task failed with exceptionTraceback (most recent call last): File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/session.py", line 72, in wrapper return func(*args, **kwargs) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 2305, in xcom_push session=session, File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/session.py", line 72, in wrapper return func(*args, **kwargs) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/xcom.py", line 240, in set map_index=map_index, File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/xcom.py", line 627, in serialize_value return json.dumps(value, cls=XComEncoder).encode("UTF-8") File "/usr/local/lib/python3.7/json/init.py", line 238, in dumps **kw).encode(obj) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/json.py", line 176, in encode return super().encode(o) File "/usr/local/lib/python3.7/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/local/lib/python3.7/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/json.py", line 153, in default CLASSNAME: o. + "." + o.., AttributeError: 'numpy.int64' object has no attribute ''
- Assistant
The error message suggests that there is an issue with the data type of the value being passed to
xcom_push. In this case, the data type causing the error isnumpy.int64.One way to resolve this issue is to convert the
numpy.int64values to regular integers before pushing them to XCom. You can do this by calling theint()function on each value in the DataFrame:pythondf = df.astype(int)By converting the values to regular integers, you should be able to push the DataFrame to XCom without encountering the error.