1"""
2compat
3======
4
5Cross-compatible functions for different versions of Python.
6
7Other items:
8* platform checker
9"""
10
11from __future__ import annotations
12
13import os
14import platform
15import sys
16from typing import TYPE_CHECKING
17
18from pandas.compat._constants import (
19 CHAINED_WARNING_DISABLED,
20 IS64,
21 ISMUSL,
22 PY312,
23 PY314,
24 PYPY,
25 WASM,
26)
27from pandas.compat.numpy import is_numpy_dev
28from pandas.compat.pyarrow import (
29 HAS_PYARROW,
30 PYARROW_INSTALLED,
31 PYARROW_MIN_VERSION,
32 pa_version_under14p0,
33 pa_version_under14p1,
34 pa_version_under16p0,
35 pa_version_under17p0,
36 pa_version_under18p0,
37 pa_version_under19p0,
38 pa_version_under20p0,
39 pa_version_under21p0,
40 pa_version_under22p0,
41 pa_version_under23p0,
42)
43
44if TYPE_CHECKING:
45 from pandas._typing import F
46
47
48def set_function_name(f: F, name: str, cls: type) -> F:
49 """
50 Bind the name/qualname attributes of the function.
51 """
52 f.__name__ = name
53 f.__qualname__ = f"{cls.__name__}.{name}"
54 f.__module__ = cls.__module__
55 return f
56
57
58def is_platform_little_endian() -> bool:
59 """
60 Checking if the running platform is little endian.
61
62 Returns
63 -------
64 bool
65 True if the running platform is little endian.
66 """
67 return sys.byteorder == "little"
68
69
70def is_platform_windows() -> bool:
71 """
72 Checking if the running platform is windows.
73
74 Returns
75 -------
76 bool
77 True if the running platform is windows.
78 """
79 return sys.platform in ["win32", "cygwin"]
80
81
82def is_platform_linux() -> bool:
83 """
84 Checking if the running platform is linux.
85
86 Returns
87 -------
88 bool
89 True if the running platform is linux.
90 """
91 return sys.platform == "linux"
92
93
94def is_platform_mac() -> bool:
95 """
96 Checking if the running platform is mac.
97
98 Returns
99 -------
100 bool
101 True if the running platform is mac.
102 """
103 return sys.platform == "darwin"
104
105
106def is_platform_arm() -> bool:
107 """
108 Checking if the running platform use ARM architecture.
109
110 Returns
111 -------
112 bool
113 True if the running platform uses ARM architecture.
114 """
115 return platform.machine() in ("arm64", "aarch64") or platform.machine().startswith(
116 "armv"
117 )
118
119
120def is_platform_power() -> bool:
121 """
122 Checking if the running platform use Power architecture.
123
124 Returns
125 -------
126 bool
127 True if the running platform uses ARM architecture.
128 """
129 return platform.machine() in ("ppc64", "ppc64le")
130
131
132def is_platform_riscv64() -> bool:
133 """
134 Checking if the running platform use riscv64 architecture.
135
136 Returns
137 -------
138 bool
139 True if the running platform uses riscv64 architecture.
140 """
141 return platform.machine() == "riscv64"
142
143
144def is_ci_environment() -> bool:
145 """
146 Checking if running in a continuous integration environment by checking
147 the PANDAS_CI environment variable.
148
149 Returns
150 -------
151 bool
152 True if the running in a continuous integration environment.
153 """
154 return os.environ.get("PANDAS_CI", "0") == "1"
155
156
157__all__ = [
158 "CHAINED_WARNING_DISABLED",
159 "HAS_PYARROW",
160 "IS64",
161 "ISMUSL",
162 "PY312",
163 "PY314",
164 "PYARROW_INSTALLED",
165 "PYARROW_MIN_VERSION",
166 "PYPY",
167 "WASM",
168 "is_numpy_dev",
169 "pa_version_under14p0",
170 "pa_version_under14p1",
171 "pa_version_under16p0",
172 "pa_version_under17p0",
173 "pa_version_under18p0",
174 "pa_version_under19p0",
175 "pa_version_under20p0",
176 "pa_version_under21p0",
177 "pa_version_under22p0",
178 "pa_version_under23p0",
179]