Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: add support for numpy2 #212

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

natsukium
Copy link
Contributor

patsy/util.py Outdated
@@ -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 link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this simplified to only the try...except? With some comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have taken the changes to scipy as they are, but I can change them.
However, try-catch is generally considered to be expensive, which is why they use if-elif first in this way, I guess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you simplify to the try...except for additional robustness then I'll merge this in.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Let's just do the try/except. Thanks for stepping in here @bashtage !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review!
I simplified it to just a try-except clause and added a comment.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 97.64%. Comparing base (8546450) to head (251951d).

Files with missing lines Patch % Lines
patsy/util.py 20.00% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #212      +/-   ##
==========================================
- Coverage   98.46%   97.64%   -0.83%     
==========================================
  Files          30       30              
  Lines        3133     3141       +8     
  Branches      693      598      -95     
==========================================
- Hits         3085     3067      -18     
- Misses         25       46      +21     
- Partials       23       28       +5     
Flag Coverage Δ
unittests 97.26% <20.00%> (-0.80%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bashtage
Copy link
Contributor

bashtage commented Nov 1, 2024

Sounds like this only affects 2.0.0dev, but not 1.26 or 2.0.0+. Is this right?

@natsukium
Copy link
Contributor Author

No, as noted in the migration guide, this is a fix for a change in the copy mode in numpy 2.0 (including dev).
It means that if it is not changed, it will not work in the latest 2.1.2.

@bashtage
Copy link
Contributor

bashtage commented Nov 1, 2024

No, as noted in the migration guide, this is a fix for a change in the copy mode in numpy 2.0 (including dev).
It means that if it is not changed, it will not work in the latest 2.1.2.

I am a bit skeptical about that. Statsmodels makes heavy use of patsy and runs on NumPy 1.22+ including 2.0.0dev, 2.1 and 2.2. Can you show that patsy fails on a version of NumPy (actual, not just based on the guide)?

@natsukium
Copy link
Contributor Author

natsukium commented Nov 1, 2024

Already reported with logs in issue, #210
I am also a python maintainer on NixOS/nixpkgs, and I got the same error.

Here's the log. The numpy version is 2.1.2.

patsy> ============================= test session starts ==============================
patsy> platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
patsy> rootdir: /build/patsy-0.5.6
patsy> configfile: setup.cfg
patsy> testpaths: patsy
patsy> collected 148 items                                                            
patsy> 
patsy> patsy/build.py .......                                                   [  4%]
patsy> patsy/builtins.py ..                                                     [  6%]
patsy> patsy/categorical.py ....                                                [  8%]
patsy> patsy/constraint.py .....                                                [ 12%]
patsy> patsy/contrasts.py .........                                             [ 18%]
patsy> patsy/desc.py ......                                                     [ 22%]
patsy> patsy/design_info.py ........                                            [ 27%]
patsy> patsy/eval.py ...............                                            [ 37%]
patsy> patsy/infix_parser.py .                                                  [ 38%]
patsy> patsy/mgcv_cubic_splines.py ............                                 [ 46%]
patsy> patsy/missing.py .....                                                   [ 50%]
patsy> patsy/origin.py .                                                        [ 50%]
patsy> patsy/parse_formula.py .....                                             [ 54%]
patsy> patsy/redundancy.py ....                                                 [ 56%]
patsy> patsy/splines.py ....                                                    [ 59%]
patsy> patsy/test_build.py .................                                    [ 70%]
patsy> patsy/test_highlevel.py F....FF...........                               [ 83%]
patsy> patsy/test_regressions.py .                                              [ 83%]
patsy> patsy/test_state.py FF.                                                  [ 85%]
patsy> patsy/tokens.py ..                                                       [ 87%]
patsy> patsy/user_util.py ...                                                   [ 89%]
patsy> patsy/util.py F...............                                           [100%]
patsy> 
patsy> =================================== FAILURES ===================================
patsy> ______________________________ test_formula_likes ______________________________
patsy> 
patsy>     def test_formula_likes():
patsy>         # Plain array-like, rhs only
patsy> >       t([[1, 2, 3], [4, 5, 6]], {}, 0,
patsy>           False,
patsy>           [[1, 2, 3], [4, 5, 6]], ["x0", "x1", "x2"])
patsy> 
patsy> patsy/test_highlevel.py:150: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/test_highlevel.py:104: in t
patsy>     rhs = f(formula_like, data, depth)
patsy> patsy/highlevel.py:290: in dmatrix
patsy>     (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
patsy> patsy/highlevel.py:181: in _do_highlevel_design
patsy>     (lhs, rhs) = (None, asarray_or_pandas(formula_like, subok=True))
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> a = [[1, 2, 3], [4, 5, 6]], copy = False, dtype = None, subok = True
patsy> 
patsy>     def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
patsy>         if have_pandas:
patsy>             if isinstance(a, (pandas.Series, pandas.DataFrame)):
patsy>                 # The .name attribute on Series is discarded when passing through
patsy>                 # the constructor:
patsy>                 #   https://github.com/pydata/pandas/issues/1578
patsy>                 extra_args = {}
patsy>                 if hasattr(a, "name"):
patsy>                     extra_args["name"] = a.name
patsy>                 return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
patsy> >       return np.array(a, copy=copy, dtype=dtype, subok=subok)
patsy> E       ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> 
patsy> patsy/util.py:67: ValueError
patsy> ________________________________ test_builtins _________________________________
patsy> 
patsy> msg = 'Error evaluating factor', origin = EvalFactor('center(x)')
patsy> f = <bound method EvalEnvironment.eval of <patsy.eval.EvalEnvironment object at 0x7fff93314c20>>
patsy> args = ('_patsy_stobj0__center__.transform(x)',)
patsy> kwargs = {'inner_namespace': VarLookupDict([{}, {'x': [1, 2, 3], 'y': [4, 5, 6], 'a b c': [10, 20, 30]}, {'_patsy_stobj0__center__': <patsy.state.Center object at 0x7fff93314950>}])}
patsy> new_exc = PatsyError('Error evaluating factor: ValueError: Unable to avoid copy while creating an array as requested.\nIf using ...r more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.')
patsy> 
patsy>     def call_and_wrap_exc(msg, origin, f, *args, **kwargs):
patsy>         try:
patsy> >           return f(*args, **kwargs)
patsy> 
patsy> patsy/compat.py:36: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/eval.py:169: in eval
patsy>     return eval(code, {}, VarLookupDict([inner_namespace]
patsy> patsy/state.py:106: in transform
patsy>     x = asarray_or_pandas(x)
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> a = [1, 2, 3], copy = False, dtype = None, subok = False
patsy> 
patsy>     def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
patsy>         if have_pandas:
patsy>             if isinstance(a, (pandas.Series, pandas.DataFrame)):
patsy>                 # The .name attribute on Series is discarded when passing through
patsy>                 # the constructor:
patsy>                 #   https://github.com/pydata/pandas/issues/1578
patsy>                 extra_args = {}
patsy>                 if hasattr(a, "name"):
patsy>                     extra_args["name"] = a.name
patsy>                 return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
patsy> >       return np.array(a, copy=copy, dtype=dtype, subok=subok)
patsy> E       ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> 
patsy> patsy/util.py:67: ValueError
patsy> 
patsy> The above exception was the direct cause of the following exception:
patsy> 
patsy>     def test_builtins():
patsy>         data = {"x": [1, 2, 3],
patsy>                 "y": [4, 5, 6],
patsy>                 "a b c": [10, 20, 30]}
patsy>         t("0 + I(x + y)", data, 0,
patsy>           True,
patsy>           [[1], [2], [3], [4], [5], [6]], ["I(x + y)"])
patsy>         t("Q('a b c')", data, 0,
patsy>           True,
patsy>           [[1, 10], [1, 20], [1, 30]], ["Intercept", "Q('a b c')"])
patsy> >       t("center(x)", data, 0,
patsy>           True,
patsy>           [[1, -1], [1, 0], [1, 1]], ["Intercept", "center(x)"])
patsy> 
patsy> patsy/test_highlevel.py:498: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/test_highlevel.py:83: in t
patsy>     builder = incr_dbuilder(formula_like, data_iter_maker, depth)
patsy> patsy/highlevel.py:111: in incr_dbuilder
patsy>     design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env,
patsy> patsy/highlevel.py:66: in _try_incr_builders
patsy>     return design_matrix_builders([formula_like.lhs_termlist,
patsy> patsy/build.py:693: in design_matrix_builders
patsy>     cat_levels_contrasts) = _examine_factor_types(all_factors,
patsy> patsy/build.py:443: in _examine_factor_types
patsy>     value = factor.eval(factor_states[factor], data)
patsy> patsy/eval.py:568: in eval
patsy>     return self._eval(memorize_state["eval_code"],
patsy> patsy/eval.py:551: in _eval
patsy>     return call_and_wrap_exc("Error evaluating factor",
patsy> patsy/compat.py:43: in call_and_wrap_exc
patsy>     exec("raise new_exc from e")
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> >   ???
patsy> E   patsy.PatsyError: Error evaluating factor: ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E   For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> E       center(x)
patsy> E       ^^^^^^^^^
patsy> 
patsy> <string>:1: PatsyError
patsy> _______________________________ test_incremental _______________________________
patsy> 
patsy> msg = 'Error evaluating factor'
patsy> origin = EvalFactor('center(np.sin(center(x)))')
patsy> f = <bound method EvalEnvironment.eval of <patsy.eval.EvalEnvironment object at 0x7fff302e7ec0>>
patsy> args = ('_patsy_stobj0__center__.memorize_chunk(np.sin(_patsy_stobj1__center__.transform(x)))',)
patsy> kwargs = {'inner_namespace': VarLookupDict([{}, {'a': ['a2', 'a2', 'a2'], 'x': [1, 2, 3]}, {'_patsy_stobj0__center__': <patsy.state.Center object at 0x7fff302e4830>, '_patsy_stobj1__center__': <patsy.state.Center object at 0x7fff302e5280>}])}
patsy> new_exc = PatsyError('Error evaluating factor: ValueError: Unable to avoid copy while creating an array as requested.\nIf using ...r more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.')
patsy> 
patsy>     def call_and_wrap_exc(msg, origin, f, *args, **kwargs):
patsy>         try:
patsy> >           return f(*args, **kwargs)
patsy> 
patsy> patsy/compat.py:36: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/eval.py:169: in eval
patsy>     return eval(code, {}, VarLookupDict([inner_namespace]
patsy> patsy/state.py:106: in transform
patsy>     x = asarray_or_pandas(x)
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> a = [1, 2, 3], copy = False, dtype = None, subok = False
patsy> 
patsy>     def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
patsy>         if have_pandas:
patsy>             if isinstance(a, (pandas.Series, pandas.DataFrame)):
patsy>                 # The .name attribute on Series is discarded when passing through
patsy>                 # the constructor:
patsy>                 #   https://github.com/pydata/pandas/issues/1578
patsy>                 extra_args = {}
patsy>                 if hasattr(a, "name"):
patsy>                     extra_args["name"] = a.name
patsy>                 return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
patsy> >       return np.array(a, copy=copy, dtype=dtype, subok=subok)
patsy> E       ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> 
patsy> patsy/util.py:67: ValueError
patsy> 
patsy> The above exception was the direct cause of the following exception:
patsy> 
patsy>     def test_incremental():
patsy>         # incr_dbuilder(s)
patsy>         # stateful transformations
patsy>         datas = [
patsy>             {"a": ["a2", "a2", "a2"],
patsy>              "x": [1, 2, 3]},
patsy>             {"a": ["a2", "a2", "a1"],
patsy>              "x": [4, 5, 6]},
patsy>             ]
patsy>         x = np.asarray([1, 2, 3, 4, 5, 6])
patsy>         sin_center_x = np.sin(x - np.mean(x))
patsy>         x_col = sin_center_x - np.mean(sin_center_x)
patsy>         def data_iter_maker():
patsy>             return iter(datas)
patsy> >       builders = incr_dbuilders("1 ~ a + center(np.sin(center(x)))",
patsy>                                   data_iter_maker)
patsy> 
patsy> patsy/test_highlevel.py:516: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/highlevel.py:129: in incr_dbuilders
patsy>     design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env,
patsy> patsy/highlevel.py:66: in _try_incr_builders
patsy>     return design_matrix_builders([formula_like.lhs_termlist,
patsy> patsy/build.py:689: in design_matrix_builders
patsy>     factor_states = _factors_memorize(all_factors, data_iter_maker, eval_env)
patsy> patsy/build.py:368: in _factors_memorize
patsy>     factor.memorize_chunk(state, which_pass, data)
patsy> patsy/eval.py:559: in memorize_chunk
patsy>     self._eval(state["memorize_code"][obj_name],
patsy> patsy/eval.py:551: in _eval
patsy>     return call_and_wrap_exc("Error evaluating factor",
patsy> patsy/compat.py:43: in call_and_wrap_exc
patsy>     exec("raise new_exc from e")
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> >   ???
patsy> E   patsy.PatsyError: Error evaluating factor: ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E   For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> E       1 ~ a + center(np.sin(center(x)))
patsy> E               ^^^^^^^^^^^^^^^^^^^^^^^^^
patsy> 
patsy> <string>:1: PatsyError
patsy> _________________________________ test_Center __________________________________
patsy> 
patsy>     def test_Center():
patsy> >       check_stateful(Center, True, [1, 2, 3], [-1, 0, 1])
patsy> 
patsy> patsy/test_state.py:117: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/test_state.py:81: in check_stateful
patsy>     output_chunk = t.transform(input_chunk, *args, **kwargs)
patsy> patsy/state.py:106: in transform
patsy>     x = asarray_or_pandas(x)
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> a = np.int64(1), copy = False, dtype = None, subok = False
patsy> 
patsy>     def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
patsy>         if have_pandas:
patsy>             if isinstance(a, (pandas.Series, pandas.DataFrame)):
patsy>                 # The .name attribute on Series is discarded when passing through
patsy>                 # the constructor:
patsy>                 #   https://github.com/pydata/pandas/issues/1578
patsy>                 extra_args = {}
patsy>                 if hasattr(a, "name"):
patsy>                     extra_args["name"] = a.name
patsy>                 return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
patsy> >       return np.array(a, copy=copy, dtype=dtype, subok=subok)
patsy> E       ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> 
patsy> patsy/util.py:67: ValueError
patsy> ----------------------------- Captured stdout call -----------------------------
patsy> [array([1, 2, 3])]
patsy> [1 2 3]
patsy> _______________________ test_stateful_transform_wrapper ________________________
patsy> 
patsy>     def test_stateful_transform_wrapper():
patsy> >       assert np.allclose(center([1, 2, 3]), [-1, 0, 1])
patsy> 
patsy> patsy/test_state.py:124: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> patsy/state.py:48: in stateful_transform_wrapper
patsy>     return transform.transform(*args, **kwargs)
patsy> patsy/state.py:106: in transform
patsy>     x = asarray_or_pandas(x)
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> a = [1, 2, 3], copy = False, dtype = None, subok = False
patsy> 
patsy>     def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
patsy>         if have_pandas:
patsy>             if isinstance(a, (pandas.Series, pandas.DataFrame)):
patsy>                 # The .name attribute on Series is discarded when passing through
patsy>                 # the constructor:
patsy>                 #   https://github.com/pydata/pandas/issues/1578
patsy>                 extra_args = {}
patsy>                 if hasattr(a, "name"):
patsy>                     extra_args["name"] = a.name
patsy>                 return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
patsy> >       return np.array(a, copy=copy, dtype=dtype, subok=subok)
patsy> E       ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> 
patsy> patsy/util.py:67: ValueError
patsy> ____________________________ test_asarray_or_pandas ____________________________
patsy> 
patsy>     def test_asarray_or_pandas():
patsy>         import warnings
patsy> >       assert type(asarray_or_pandas([1, 2, 3])) is np.ndarray
patsy> 
patsy> patsy/util.py:72: 
patsy> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
patsy> 
patsy> a = [1, 2, 3], copy = False, dtype = None, subok = False
patsy> 
patsy>     def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
patsy>         if have_pandas:
patsy>             if isinstance(a, (pandas.Series, pandas.DataFrame)):
patsy>                 # The .name attribute on Series is discarded when passing through
patsy>                 # the constructor:
patsy>                 #   https://github.com/pydata/pandas/issues/1578
patsy>                 extra_args = {}
patsy>                 if hasattr(a, "name"):
patsy>                     extra_args["name"] = a.name
patsy>                 return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
patsy> >       return np.array(a, copy=copy, dtype=dtype, subok=subok)
patsy> E       ValueError: Unable to avoid copy while creating an array as requested.
patsy> 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).
patsy> E       For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.
patsy> 
patsy> patsy/util.py:67: ValueError
patsy> =========================== short test summary info ============================
patsy> FAILED patsy/test_highlevel.py::test_formula_likes - ValueError: Unable to avoid copy while creating an array as requested.
patsy> FAILED patsy/test_highlevel.py::test_builtins - patsy.PatsyError: Error evaluating factor: ValueError: Unable to avoid copy...
patsy> FAILED patsy/test_highlevel.py::test_incremental - patsy.PatsyError: Error evaluating factor: ValueError: Unable to avoid copy...
patsy> FAILED patsy/test_state.py::test_Center - ValueError: Unable to avoid copy while creating an array as requested.
patsy> FAILED patsy/test_state.py::test_stateful_transform_wrapper - ValueError: Unable to avoid copy while creating an array as requested.
patsy> FAILED patsy/util.py::test_asarray_or_pandas - ValueError: Unable to avoid copy while creating an array as requested.
patsy> =================== 6 failed, 142 passed in 88.39s (0:01:28) ===================

@matthewwardrop
Copy link
Collaborator

Thanks for updating the patch, @natsukium . Merging it in.

@matthewwardrop matthewwardrop merged commit 9fba33e into pydata:master Nov 11, 2024
14 of 15 checks passed
@natsukium natsukium deleted the numpy2 branch November 12, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failures with NumPy 2.0.0
4 participants