This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new d65cd6c6ec5 Fix compatibility with new numpy and pandas (#52071)
d65cd6c6ec5 is described below

commit d65cd6c6ec57854b5d5f6f2b19a4791662a4fa02
Author: Jarek Potiuk <[email protected]>
AuthorDate: Mon Jun 23 11:16:18 2025 +0200

    Fix compatibility with new numpy and pandas (#52071)
    
    After #52060 some tests started to fail - this PR fixes it:
    
    * test_pandas.py is removed, it makes no sense as we seem to be
      testing if pandas has specific API (which we neither use nor
      guarantee)
    
    * numpy serializers are now compatible with numpy 2
---
 airflow-core/tests/unit/always/test_pandas.py      | 59 ----------------------
 .../serialization/serializers/test_serializers.py  | 10 +++-
 2 files changed, 8 insertions(+), 61 deletions(-)

diff --git a/airflow-core/tests/unit/always/test_pandas.py 
b/airflow-core/tests/unit/always/test_pandas.py
deleted file mode 100644
index 5e474392dd8..00000000000
--- a/airflow-core/tests/unit/always/test_pandas.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-from __future__ import annotations
-
-import pytest
-from sqlalchemy import create_engine
-
-from airflow.configuration import conf
-
-pd = pytest.importorskip("pandas")
-pyarrow = pytest.importorskip("pyarrow")
-
-pytestmark = pytest.mark.db_test
-
-
[email protected]("postgres", "mysql")
-class TestPandasSQLAlchemyCompatibility:
-    @pytest.fixture(autouse=True)
-    def _setup_test_cases(self):
-        self.temp_table = "test_to_pandas"
-        uri = conf.get_mandatory_value("database", "sql_alchemy_conn")
-        self.engine = create_engine(uri)
-        yield
-        if self.engine:
-            with self.engine.begin() as conn:
-                conn.execute(f"DROP TABLE IF EXISTS {self.temp_table};")
-            self.engine.dispose()
-
-    def test_write_read_to_db(self):
-        pd.DataFrame({"a": [0, 1, 2, 3]}).to_sql(self.temp_table, self.engine)
-        pd.read_sql(f"SELECT * FROM {self.temp_table}", self.engine)
-
-
-class TestPandasSQLAlchemyCompatibilitySQLite:
-    @pytest.fixture(autouse=True)
-    def _setup_test_cases(self):
-        self.temp_table = "test_to_pandas"
-        self.engine = create_engine("sqlite:///:memory:")
-        yield
-        if self.engine:
-            self.engine.dispose()
-
-    def test_write_read_to_db(self):
-        pd.DataFrame({"a": [0, 1, 2, 3]}).to_sql(self.temp_table, self.engine)
-        pd.read_sql(f"SELECT * FROM {self.temp_table}", self.engine)
diff --git 
a/airflow-core/tests/unit/serialization/serializers/test_serializers.py 
b/airflow-core/tests/unit/serialization/serializers/test_serializers.py
index 6cc6505d48b..8aa62548169 100644
--- a/airflow-core/tests/unit/serialization/serializers/test_serializers.py
+++ b/airflow-core/tests/unit/serialization/serializers/test_serializers.py
@@ -222,8 +222,14 @@ class TestSerializers:
     def test_numpy_serializers(self):
         from airflow.serialization.serializers.numpy import serialize
 
-        assert serialize(np.bool_(False)) == (True, "numpy.bool_", 1, True)
-        assert serialize(np.float32(3.14)) == (float(np.float32(3.14)), 
"numpy.float32", 1, True)
+        numpy_version = metadata.version("numpy")
+        is_numpy_2 = version.parse(numpy_version).major == 2
+
+        assert serialize(np.bool_(False)) == (True, "numpy.bool" if is_numpy_2 
else "numpy.bool_", 1, True)
+        if is_numpy_2:
+            assert serialize(np.float64(3.14)) == (float(np.float64(3.14)), 
"numpy.float64", 1, True)
+        else:
+            assert serialize(np.float32(3.14)) == (float(np.float32(3.14)), 
"numpy.float32", 1, True)
         assert serialize(np.array([1, 2, 3])) == ("", "", 0, False)
 
     @pytest.mark.parametrize(

Reply via email to