terrier-org / pyterrier

A Python framework for performing information retrieval experiments, building on http://terrier.org/
https://pyterrier.readthedocs.io/
Mozilla Public License 2.0
397 stars 63 forks source link

Remove nptyping dependency to assure numpy 2 compatability #445

Closed cmacdonald closed 3 weeks ago

cmacdonald commented 4 weeks ago

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 commented 4 weeks ago

I vote we drop the dependency. We only use it here https://github.com/terrier-org/pyterrier/blob/a17f9b7ed1782010b4680457874f220b65fa2594/pyterrier/apply.py#L91 and we can just use np.array hint instead in that spot.