aports/community/py3-patsy/numpy2-array.patch
mio 47bdd581bd community/py3-patsy: fix tests with numpy 2.0
Update numpy array copy references for numpy 2.0 compatibility to fix
failed tests.

```
a = [1, 2, 3], copy = False, dtype = None, subok = False

    def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
        if have_pandas:
            if isinstance(a, (pandas.Series, pandas.DataFrame)):
                # The .name attribute on Series is discarded when passing through
                # the constructor:
                #   https://github.com/pydata/pandas/issues/1578
                extra_args = {}
                if hasattr(a, "name"):
                    extra_args["name"] = a.name
                return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
>       return np.array(a, copy=copy, dtype=dtype, subok=subok)
E       ValueError: Unable to avoid copy while creating an array as requested.
E       If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).
E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

patsy/util.py:67: ValueError
```
2024-11-05 08:58:57 +00:00

40 lines
1.5 KiB
Diff

Source: https://github.com/pydata/patsy/pull/212.patch
--
From 251951dd7a4116be1cd34963780b87b4a67b79ae Mon Sep 17 00:00:00 2001
From: natsukium <tomoya.otabi@gmail.com>
Date: Fri, 1 Nov 2024 20:30:03 +0900
Subject: [PATCH] MAINT: add support for numpy2
https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword
---
patsy/util.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/patsy/util.py b/patsy/util.py
index 3116e11..6024242 100644
--- a/patsy/util.py
+++ b/patsy/util.py
@@ -52,9 +52,21 @@
"is_categorical_dtype", None)
have_pandas_categorical_dtype = _pandas_is_categorical_dtype is not None
+if np.lib.NumpyVersion(np.__version__) >= "2.0.0":
+ copy_if_needed = None
+elif np.lib.NumpyVersion(np.__version__) < "1.28.0":
+ copy_if_needed = False
+else:
+ # 2.0.0 dev versions, handle cases where copy may or may not exist
+ try:
+ np.array([1]).__array__(copy=None)
+ copy_if_needed = None
+ except TypeError:
+ copy_if_needed = False
+
# Passes through Series and DataFrames, call np.asarray() on everything else
-def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
+def asarray_or_pandas(a, copy=copy_if_needed, dtype=None, subok=False):
if have_pandas:
if isinstance(a, (pandas.Series, pandas.DataFrame)):
# The .name attribute on Series is discarded when passing through