Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/compat/__init__.py : 70%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2compat
3======
5Cross-compatible functions for different versions of Python.
7Other items:
8* platform checker
9"""
10import platform
11import struct
12import sys
13import warnings
15PY37 = sys.version_info >= (3, 7)
16PY38 = sys.version_info >= (3, 8)
17PYPY = platform.python_implementation() == "PyPy"
20# ----------------------------------------------------------------------------
21# functions largely based / taken from the six module
23# Much of the code in this module comes from Benjamin Peterson's six library.
24# The license for this library can be found in LICENSES/SIX and the code can be
25# found at https://bitbucket.org/gutworth/six
28def set_function_name(f, name, cls):
29 """
30 Bind the name/qualname attributes of the function.
31 """
32 f.__name__ = name
33 f.__qualname__ = f"{cls.__name__}.{name}"
34 f.__module__ = cls.__module__
35 return f
38# https://github.com/pandas-dev/pandas/pull/9123
39def is_platform_little_endian() -> bool:
40 """
41 Checking if the running platform is little endian.
43 Returns
44 -------
45 bool
46 True if the running platform is little endian.
47 """
48 return sys.byteorder == "little"
51def is_platform_windows() -> bool:
52 """
53 Checking if the running platform is windows.
55 Returns
56 -------
57 bool
58 True if the running platform is windows.
59 """
60 return sys.platform == "win32" or sys.platform == "cygwin"
63def is_platform_linux() -> bool:
64 """
65 Checking if the running platform is linux.
67 Returns
68 -------
69 bool
70 True if the running platform is linux.
71 """
72 return sys.platform == "linux2"
75def is_platform_mac() -> bool:
76 """
77 Checking if the running platform is mac.
79 Returns
80 -------
81 bool
82 True if the running platform is mac.
83 """
84 return sys.platform == "darwin"
87def is_platform_32bit() -> bool:
88 """
89 Checking if the running platform is 32-bit.
91 Returns
92 -------
93 bool
94 True if the running platform is 32-bit.
95 """
96 return struct.calcsize("P") * 8 < 64
99def _import_lzma():
100 """
101 Importing the `lzma` module.
103 Warns
104 -----
105 When the `lzma` module is not available.
106 """
107 try:
108 import lzma
110 return lzma
111 except ImportError:
112 msg = (
113 "Could not import the lzma module. "
114 "Your installed Python is incomplete. "
115 "Attempting to use lzma compression will result in a RuntimeError."
116 )
117 warnings.warn(msg)
120def _get_lzma_file(lzma):
121 """
122 Importing the `LZMAFile` class from the `lzma` module.
124 Returns
125 -------
126 class
127 The `LZMAFile` class from the `lzma` module.
129 Raises
130 ------
131 RuntimeError
132 If the `lzma` module was not imported correctly, or didn't exist.
133 """
134 if lzma is None:
135 raise RuntimeError(
136 "lzma module not available. "
137 "A Python re-install with the proper dependencies, "
138 "might be required to solve this issue."
139 )
140 return lzma.LZMAFile