__init__.py 1.3 KB

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