forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
195 lines (157 loc) · 4.07 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""
compat
======
Cross-compatible functions for different versions of Python.
Other items:
* platform checker
"""
from __future__ import annotations
import os
import platform
import sys
from typing import TYPE_CHECKING
from pandas.compat._constants import (
IS64,
ISMUSL,
PY310,
PY311,
PY312,
PYPY,
)
import pandas.compat.compressors
from pandas.compat.numpy import is_numpy_dev
from pandas.compat.pyarrow import (
pa_version_under7p0,
pa_version_under8p0,
pa_version_under9p0,
pa_version_under11p0,
pa_version_under13p0,
)
if TYPE_CHECKING:
from pandas._typing import F
def set_function_name(f: F, name: str, cls: type) -> F:
"""
Bind the name/qualname attributes of the function.
"""
f.__name__ = name
f.__qualname__ = f"{cls.__name__}.{name}"
f.__module__ = cls.__module__
return f
def is_platform_little_endian() -> bool:
"""
Checking if the running platform is little endian.
Returns
-------
bool
True if the running platform is little endian.
"""
return sys.byteorder == "little"
def is_platform_windows() -> bool:
"""
Checking if the running platform is windows.
Returns
-------
bool
True if the running platform is windows.
"""
return sys.platform in ["win32", "cygwin"]
def is_platform_linux() -> bool:
"""
Checking if the running platform is linux.
Returns
-------
bool
True if the running platform is linux.
"""
return sys.platform == "linux"
def is_platform_mac() -> bool:
"""
Checking if the running platform is mac.
Returns
-------
bool
True if the running platform is mac.
"""
return sys.platform == "darwin"
def is_platform_arm() -> bool:
"""
Checking if the running platform use ARM architecture.
Returns
-------
bool
True if the running platform uses ARM architecture.
"""
return platform.machine() in ("arm64", "aarch64") or platform.machine().startswith(
"armv"
)
def is_platform_power() -> bool:
"""
Checking if the running platform use Power architecture.
Returns
-------
bool
True if the running platform uses ARM architecture.
"""
return platform.machine() in ("ppc64", "ppc64le")
def is_ci_environment() -> bool:
"""
Checking if running in a continuous integration environment by checking
the PANDAS_CI environment variable.
Returns
-------
bool
True if the running in a continuous integration environment.
"""
return os.environ.get("PANDAS_CI", "0") == "1"
def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]:
"""
Importing the `LZMAFile` class from the `lzma` module.
Returns
-------
class
The `LZMAFile` class from the `lzma` module.
Raises
------
RuntimeError
If the `lzma` module was not imported correctly, or didn't exist.
"""
if not pandas.compat.compressors.has_lzma:
raise RuntimeError(
"lzma module not available. "
"A Python re-install with the proper dependencies, "
"might be required to solve this issue."
)
return pandas.compat.compressors.LZMAFile
def get_bz2_file() -> type[pandas.compat.compressors.BZ2File]:
"""
Importing the `BZ2File` class from the `bz2` module.
Returns
-------
class
The `BZ2File` class from the `bz2` module.
Raises
------
RuntimeError
If the `bz2` module was not imported correctly, or didn't exist.
"""
if not pandas.compat.compressors.has_bz2:
raise RuntimeError(
"bz2 module not available. "
"A Python re-install with the proper dependencies, "
"might be required to solve this issue."
)
return pandas.compat.compressors.BZ2File
__all__ = [
"is_numpy_dev",
"pa_version_under7p0",
"pa_version_under8p0",
"pa_version_under9p0",
"pa_version_under11p0",
"pa_version_under13p0",
"IS64",
"ISMUSL",
"PY310",
"PY311",
"PY312",
"PYPY",
]