forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
141 lines (109 loc) · 2.99 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
"""
compat
======
Cross-compatible functions for different versions of Python.
Other items:
* platform checker
"""
import platform
import struct
import sys
import warnings
from pandas._typing import F
PY37 = sys.version_info >= (3, 7)
PY38 = sys.version_info >= (3, 8)
PYPY = platform.python_implementation() == "PyPy"
# ----------------------------------------------------------------------------
# functions largely based / taken from the six module
# Much of the code in this module comes from Benjamin Peterson's six library.
# The license for this library can be found in LICENSES/SIX and the code can be
# found at https://bitbucket.org/gutworth/six
def set_function_name(f: F, name: str, cls) -> F:
"""
Bind the name/qualname attributes of the function.
"""
f.__name__ = name
f.__qualname__ = f"{cls.__name__}.{name}"
f.__module__ = cls.__module__
return f
# https://github.com/pandas-dev/pandas/pull/9123
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 == "win32" or sys.platform == "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 == "linux2"
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_32bit() -> bool:
"""
Checking if the running platform is 32-bit.
Returns
-------
bool
True if the running platform is 32-bit.
"""
return struct.calcsize("P") * 8 < 64
def _import_lzma():
"""
Importing the `lzma` module.
Warns
-----
When the `lzma` module is not available.
"""
try:
import lzma
return lzma
except ImportError:
msg = (
"Could not import the lzma module. Your installed Python is incomplete. "
"Attempting to use lzma compression will result in a RuntimeError."
)
warnings.warn(msg)
def _get_lzma_file(lzma):
"""
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 lzma is None:
raise RuntimeError(
"lzma module not available. "
"A Python re-install with the proper dependencies, "
"might be required to solve this issue."
)
return lzma.LZMAFile