Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/pandas/compat/__init__.py: 59%

39 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1""" 

2compat 

3====== 

4 

5Cross-compatible functions for different versions of Python. 

6 

7Other items: 

8* platform checker 

9""" 

10from __future__ import annotations 

11 

12import os 

13import platform 

14import sys 

15from typing import TYPE_CHECKING 

16 

17from pandas._typing import F 

18from pandas.compat.numpy import ( 

19 is_numpy_dev, 

20 np_version_under1p21, 

21) 

22from pandas.compat.pyarrow import ( 

23 pa_version_under1p01, 

24 pa_version_under2p0, 

25 pa_version_under3p0, 

26 pa_version_under4p0, 

27 pa_version_under5p0, 

28 pa_version_under6p0, 

29 pa_version_under7p0, 

30 pa_version_under8p0, 

31 pa_version_under9p0, 

32) 

33 

34if TYPE_CHECKING: 34 ↛ 35line 34 didn't jump to line 35, because the condition on line 34 was never true

35 import lzma 

36 

37PY39 = sys.version_info >= (3, 9) 

38PY310 = sys.version_info >= (3, 10) 

39PY311 = sys.version_info >= (3, 11) 

40PYPY = platform.python_implementation() == "PyPy" 

41IS64 = sys.maxsize > 2**32 

42 

43 

44def set_function_name(f: F, name: str, cls) -> F: 

45 """ 

46 Bind the name/qualname attributes of the function. 

47 """ 

48 f.__name__ = name 

49 f.__qualname__ = f"{cls.__name__}.{name}" 

50 f.__module__ = cls.__module__ 

51 return f 

52 

53 

54def is_platform_little_endian() -> bool: 

55 """ 

56 Checking if the running platform is little endian. 

57 

58 Returns 

59 ------- 

60 bool 

61 True if the running platform is little endian. 

62 """ 

63 return sys.byteorder == "little" 

64 

65 

66def is_platform_windows() -> bool: 

67 """ 

68 Checking if the running platform is windows. 

69 

70 Returns 

71 ------- 

72 bool 

73 True if the running platform is windows. 

74 """ 

75 return sys.platform in ["win32", "cygwin"] 

76 

77 

78def is_platform_linux() -> bool: 

79 """ 

80 Checking if the running platform is linux. 

81 

82 Returns 

83 ------- 

84 bool 

85 True if the running platform is linux. 

86 """ 

87 return sys.platform == "linux" 

88 

89 

90def is_platform_mac() -> bool: 

91 """ 

92 Checking if the running platform is mac. 

93 

94 Returns 

95 ------- 

96 bool 

97 True if the running platform is mac. 

98 """ 

99 return sys.platform == "darwin" 

100 

101 

102def is_platform_arm() -> bool: 

103 """ 

104 Checking if the running platform use ARM architecture. 

105 

106 Returns 

107 ------- 

108 bool 

109 True if the running platform uses ARM architecture. 

110 """ 

111 return platform.machine() in ("arm64", "aarch64") or platform.machine().startswith( 

112 "armv" 

113 ) 

114 

115 

116def is_ci_environment() -> bool: 

117 """ 

118 Checking if running in a continuous integration environment by checking 

119 the PANDAS_CI environment variable. 

120 

121 Returns 

122 ------- 

123 bool 

124 True if the running in a continuous integration environment. 

125 """ 

126 return os.environ.get("PANDAS_CI", "0") == "1" 

127 

128 

129def get_lzma_file() -> type[lzma.LZMAFile]: 

130 """ 

131 Importing the `LZMAFile` class from the `lzma` module. 

132 

133 Returns 

134 ------- 

135 class 

136 The `LZMAFile` class from the `lzma` module. 

137 

138 Raises 

139 ------ 

140 RuntimeError 

141 If the `lzma` module was not imported correctly, or didn't exist. 

142 """ 

143 try: 

144 import lzma 

145 except ImportError: 

146 raise RuntimeError( 

147 "lzma module not available. " 

148 "A Python re-install with the proper dependencies, " 

149 "might be required to solve this issue." 

150 ) 

151 return lzma.LZMAFile 

152 

153 

154__all__ = [ 

155 "is_numpy_dev", 

156 "np_version_under1p21", 

157 "pa_version_under1p01", 

158 "pa_version_under2p0", 

159 "pa_version_under3p0", 

160 "pa_version_under4p0", 

161 "pa_version_under5p0", 

162 "pa_version_under6p0", 

163 "pa_version_under7p0", 

164 "pa_version_under8p0", 

165 "pa_version_under9p0", 

166]