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

Remove nptyping dependency to assure numpy 2 compatability #445

Merged
merged 3 commits into from
Jun 27, 2024

Conversation

cmacdonald
Copy link
Contributor

No description provided.

@cmacdonald
Copy link
Contributor Author

ile /opt/miniconda3/envs/genir/lib/python3.9/site-packages/pyterrier/apply.py:3
1 from typing import Callable, Any, Dict, Union, Sequence
2 from .apply_base import ApplyDocumentScoringTransformer, ApplyQueryTransformer, ApplyDocFeatureTransformer, ApplyForEachQuery, ApplyGenericTransformer, Transformer
----> 3 from nptyping import NDArray
4 import pandas as pd
6 def _bind(instance, func, as_name=None):

File /opt/miniconda3/envs/genir/lib/python3.9/site-packages/nptyping/init.py:2
1 from nptyping._meta import version
----> 2 from nptyping.functions._get_type import get_type
3 from nptyping.functions._py_type import py_type
4 from nptyping.types._bool import Bool

File /opt/miniconda3/envs/genir/lib/python3.9/site-packages/nptyping/functions/_get_type.py:29
27 from nptyping.types._subarray_type import SubArrayType, is_subarray_type
28 from nptyping.types._timedelta64 import Timedelta64
---> 29 from nptyping.types._unicode import Unicode
32 def get_type(obj: Any) -> Type['NPType']:
33 """
34 Return the nptyping type of the given obj. The given obj can be a numpy
35 ndarray, a dtype or a Python type. If no corresponding nptyping type
(...)
38 :return: a subclass of NPType.
39 """

File /opt/miniconda3/envs/genir/lib/python3.9/site-packages/nptyping/types/_unicode.py:30
26 return cls.chars is Any or subclass.chars <= cls.chars
27 return False
---> 30 class Unicode(NPType, np.compat.unicode, metaclass=_UnicodeMeta):
31 """
32 A numpy unicode. Can be given the number of characters optionally.
33
34 >>> Unicode[50]
35 Unicode[50]
36 """
37 chars = Any

File /opt/miniconda3/envs/genir/lib/python3.9/site-packages/numpy/init.py:397, in getattr(attr)
394 raise AttributeError(former_attrs[attr])
396 if attr in expired_attributes:
--> 397 raise AttributeError(
398 f"np.{attr} was removed in the NumPy 2.0 release. "
399 f"{expired_attributes[attr]}"
400 )
402 if attr == "chararray":
403 warnings.warn(
404 "np.chararray is deprecated and will be removed from "
405 "the main namespace in the future. Use an array with a string "
406 "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: np.compat was removed in the NumPy 2.0 release. There's no replacement, as Python 2 is no longer supported.

@seanmacavaney
Copy link
Collaborator

I vote we drop the dependency. We only use it here

def doc_features(fn : Callable[[pd.Series], NDArray[Any]], *args, **kwargs) -> Transformer:
and we can just use np.array hint instead in that spot.

@cmacdonald cmacdonald changed the title allow more modern nptyping Remove nptyping dependency to assure numpy 2 compatability Jun 27, 2024
@cmacdonald cmacdonald merged commit 308e3d7 into master Jun 27, 2024
14 checks passed
@cmacdonald cmacdonald deleted the nptyping branch June 27, 2024 09:56
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.

2 participants