sjyangkevin opened a new issue, #52753:
URL: https://github.com/apache/airflow/issues/52753

   ### Apache Airflow version
   
   3.0.2
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   When `numpy` is upgraded to 2.0 and greater version. The `numpy.bool_` 
objects cannot be serialized/deserialized. It is because the qualified name is 
resolved to `numpy.bool` instead of `numpy.bool_` while the serializers scan 
for `numpy.bool_`. As shown below:
   
https://github.com/apache/airflow/blob/2b90db5c1e50393de2e6b9e39bd79f05d357f6f3/airflow-core/src/airflow/serialization/serializers/numpy.py#L34
   
   Therefore, this object is not matched to any of the serializer and return 
`TypeError: cannot serialize object of type <class 'numpy.bool'>`
   
   When numpy version is 1.26.4, the qualified name is resolved to `numpy.bool_`
   
![Image](https://github.com/user-attachments/assets/898a070a-6f53-42a5-994b-18a2851a543b)
   When numpy version is 2.2.6, the qualified name is resolved to `numpy.bool`
   
![Image](https://github.com/user-attachments/assets/4d1a64e1-7f3b-4ea2-9f66-3768ee4b8d97)
   
   ### What you think should happen instead?
   
   `numpy.bool_` objects should be serialized/deserialized when it is passed 
through XComs.
   
   ### How to reproduce
   
   The DAG code to reproduce the error.
   
   ```python
   from airflow.decorators import dag, task
   from pendulum import datetime
   
   
   @dag(
       start_date=datetime(2025, 5, 23),
       schedule=None,
       catchup=False,
       tags=["serialization", "airflow"],
   )
   def pydantic_serde():
   
       # 5. NumPy scalar types - misc
       @task
       def get_numpy_misc():
           import numpy as np
           print(np.__version__)
           print(type(np.bool_(False)))
           print(np.bool_.__name__)
           return {
               "bool_": np.bool_(False),
               "float16": np.float16(0.125),
               "float64": np.float64(3.14159),
               "complex64": np.complex64(1 + 2j),
               "complex128": np.complex128(3 + 4j),
           }
   
       @task
       def print_numpy_misc(obj):
           print("NumPy Misc Types:")
           for k, v in obj.items():
               print(f"{k}: {v} ({type(v)})")
   
       # DAG chaining
       print_numpy_misc(get_numpy_misc())
   
   pydantic_serde()
   ```
   
   
   
   ### Operating System
   
   Ubuntu 22.04.3 LTS
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Docker-Compose
   
   ### Deployment details
   
   I run Airflow in Docker by following the guide. We need to update the 
`docker-compose.yaml` to build from the following Docker image. We can create a 
requirements.txt to install numpy 2.2.6
   
https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html
   
   ```Dockerfile
   FROM apache/airflow:3.0.2
   
   COPY requirements.txt requirements.txt
   
   RUN pip install --no-cache-dir -r requirements.txt
   
   USER ${AIRFLOW_UID}
   ```
   
   requirements.txt
   ```
   numpy==2.2.6
   ```
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to