Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pandas/compat/__init__.py: 58%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

33 statements  

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 

15 

16from pandas._typing import F 

17from pandas.compat._constants import ( 

18 IS64, 

19 PY39, 

20 PY310, 

21 PY311, 

22 PYPY, 

23) 

24import pandas.compat.compressors 

25from pandas.compat.numpy import ( 

26 is_numpy_dev, 

27 np_version_under1p21, 

28) 

29from pandas.compat.pyarrow import ( 

30 pa_version_under7p0, 

31 pa_version_under8p0, 

32 pa_version_under9p0, 

33 pa_version_under11p0, 

34) 

35 

36 

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

38 """ 

39 Bind the name/qualname attributes of the function. 

40 """ 

41 f.__name__ = name 

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

43 f.__module__ = cls.__module__ 

44 return f 

45 

46 

47def is_platform_little_endian() -> bool: 

48 """ 

49 Checking if the running platform is little endian. 

50 

51 Returns 

52 ------- 

53 bool 

54 True if the running platform is little endian. 

55 """ 

56 return sys.byteorder == "little" 

57 

58 

59def is_platform_windows() -> bool: 

60 """ 

61 Checking if the running platform is windows. 

62 

63 Returns 

64 ------- 

65 bool 

66 True if the running platform is windows. 

67 """ 

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

69 

70 

71def is_platform_linux() -> bool: 

72 """ 

73 Checking if the running platform is linux. 

74 

75 Returns 

76 ------- 

77 bool 

78 True if the running platform is linux. 

79 """ 

80 return sys.platform == "linux" 

81 

82 

83def is_platform_mac() -> bool: 

84 """ 

85 Checking if the running platform is mac. 

86 

87 Returns 

88 ------- 

89 bool 

90 True if the running platform is mac. 

91 """ 

92 return sys.platform == "darwin" 

93 

94 

95def is_platform_arm() -> bool: 

96 """ 

97 Checking if the running platform use ARM architecture. 

98 

99 Returns 

100 ------- 

101 bool 

102 True if the running platform uses ARM architecture. 

103 """ 

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

105 "armv" 

106 ) 

107 

108 

109def is_platform_power() -> bool: 

110 """ 

111 Checking if the running platform use Power architecture. 

112 

113 Returns 

114 ------- 

115 bool 

116 True if the running platform uses ARM architecture. 

117 """ 

118 return platform.machine() in ("ppc64", "ppc64le") 

119 

120 

121def is_ci_environment() -> bool: 

122 """ 

123 Checking if running in a continuous integration environment by checking 

124 the PANDAS_CI environment variable. 

125 

126 Returns 

127 ------- 

128 bool 

129 True if the running in a continuous integration environment. 

130 """ 

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

132 

133 

134def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]: 

135 """ 

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

137 

138 Returns 

139 ------- 

140 class 

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

142 

143 Raises 

144 ------ 

145 RuntimeError 

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

147 """ 

148 if not pandas.compat.compressors.has_lzma: 

149 raise RuntimeError( 

150 "lzma module not available. " 

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

152 "might be required to solve this issue." 

153 ) 

154 return pandas.compat.compressors.LZMAFile 

155 

156 

157__all__ = [ 

158 "is_numpy_dev", 

159 "np_version_under1p21", 

160 "pa_version_under7p0", 

161 "pa_version_under8p0", 

162 "pa_version_under9p0", 

163 "pa_version_under11p0", 

164 "IS64", 

165 "PY39", 

166 "PY310", 

167 "PY311", 

168 "PYPY", 

169]