1""" support numpy compatibility across versions """
2import warnings
3
4import numpy as np
5
6from pandas.util.version import Version
7
8# numpy versioning
9_np_version = np.__version__
10_nlv = Version(_np_version)
11np_version_lt1p23 = _nlv < Version("1.23")
12np_version_gte1p24 = _nlv >= Version("1.24")
13np_version_gte1p24p3 = _nlv >= Version("1.24.3")
14np_version_gte1p25 = _nlv >= Version("1.25")
15np_version_gt2 = _nlv >= Version("2.0.0")
16is_numpy_dev = _nlv.dev is not None
17_min_numpy_ver = "1.22.4"
18
19
20if _nlv < Version(_min_numpy_ver):
21 raise ImportError(
22 f"this version of pandas is incompatible with numpy < {_min_numpy_ver}\n"
23 f"your numpy version is {_np_version}.\n"
24 f"Please upgrade numpy to >= {_min_numpy_ver} to use this pandas version"
25 )
26
27
28np_long: type
29np_ulong: type
30
31if np_version_gt2:
32 try:
33 with warnings.catch_warnings():
34 warnings.filterwarnings(
35 "ignore",
36 r".*In the future `np\.long` will be defined as.*",
37 FutureWarning,
38 )
39 np_long = np.long # type: ignore[attr-defined]
40 np_ulong = np.ulong # type: ignore[attr-defined]
41 except AttributeError:
42 np_long = np.int_
43 np_ulong = np.uint
44else:
45 np_long = np.int_
46 np_ulong = np.uint
47
48
49__all__ = [
50 "np",
51 "_np_version",
52 "is_numpy_dev",
53]