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

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""" 

10 

11from __future__ import annotations 

12 

13import os 

14import platform 

15import sys 

16from typing import TYPE_CHECKING 

17 

18from pandas.compat._constants import ( 

19 CHAINED_WARNING_DISABLED, 

20 IS64, 

21 ISMUSL, 

22 PY312, 

23 PY314, 

24 PY315, 

25 PYPY, 

26 WASM, 

27) 

28from pandas.compat.numpy import is_numpy_dev 

29from pandas.compat.pyarrow import ( 

30 HAS_PYARROW, 

31 PYARROW_INSTALLED, 

32 PYARROW_MIN_VERSION, 

33 pa_version_under14p0, 

34 pa_version_under14p1, 

35 pa_version_under16p0, 

36 pa_version_under17p0, 

37 pa_version_under18p0, 

38 pa_version_under19p0, 

39 pa_version_under20p0, 

40 pa_version_under21p0, 

41 pa_version_under22p0, 

42 pa_version_under23p0, 

43 pa_version_under25p0, 

44 pa_version_under26p0, 

45) 

46 

47if TYPE_CHECKING: 

48 from pandas._typing import F 

49 

50 

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

52 """ 

53 Bind the name/qualname attributes of the function. 

54 """ 

55 f.__name__ = name 

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

57 f.__module__ = cls.__module__ 

58 return f 

59 

60 

61def is_platform_little_endian() -> bool: 

62 """ 

63 Checking if the running platform is little endian. 

64 

65 Returns 

66 ------- 

67 bool 

68 True if the running platform is little endian. 

69 """ 

70 return sys.byteorder == "little" 

71 

72 

73def is_platform_windows() -> bool: 

74 """ 

75 Checking if the running platform is windows. 

76 

77 Returns 

78 ------- 

79 bool 

80 True if the running platform is windows. 

81 """ 

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

83 

84 

85def is_platform_linux() -> bool: 

86 """ 

87 Checking if the running platform is linux. 

88 

89 Returns 

90 ------- 

91 bool 

92 True if the running platform is linux. 

93 """ 

94 return sys.platform == "linux" 

95 

96 

97def is_platform_mac() -> bool: 

98 """ 

99 Checking if the running platform is mac. 

100 

101 Returns 

102 ------- 

103 bool 

104 True if the running platform is mac. 

105 """ 

106 return sys.platform == "darwin" 

107 

108 

109def is_platform_arm() -> bool: 

110 """ 

111 Checking if the running platform use ARM architecture. 

112 

113 Returns 

114 ------- 

115 bool 

116 True if the running platform uses ARM architecture. 

117 """ 

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

119 "armv" 

120 ) 

121 

122 

123def is_platform_power() -> bool: 

124 """ 

125 Checking if the running platform use Power architecture. 

126 

127 Returns 

128 ------- 

129 bool 

130 True if the running platform uses ARM architecture. 

131 """ 

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

133 

134 

135def is_platform_riscv64() -> bool: 

136 """ 

137 Checking if the running platform use riscv64 architecture. 

138 

139 Returns 

140 ------- 

141 bool 

142 True if the running platform uses riscv64 architecture. 

143 """ 

144 return platform.machine() == "riscv64" 

145 

146 

147def is_ci_environment() -> bool: 

148 """ 

149 Checking if running in a continuous integration environment by checking 

150 the PANDAS_CI environment variable. 

151 

152 Returns 

153 ------- 

154 bool 

155 True if the running in a continuous integration environment. 

156 """ 

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

158 

159 

160__all__ = [ 

161 "CHAINED_WARNING_DISABLED", 

162 "HAS_PYARROW", 

163 "IS64", 

164 "ISMUSL", 

165 "PY312", 

166 "PY314", 

167 "PY315", 

168 "PYARROW_INSTALLED", 

169 "PYARROW_MIN_VERSION", 

170 "PYPY", 

171 "WASM", 

172 "is_numpy_dev", 

173 "pa_version_under14p0", 

174 "pa_version_under14p1", 

175 "pa_version_under16p0", 

176 "pa_version_under17p0", 

177 "pa_version_under18p0", 

178 "pa_version_under19p0", 

179 "pa_version_under20p0", 

180 "pa_version_under21p0", 

181 "pa_version_under22p0", 

182 "pa_version_under23p0", 

183 "pa_version_under25p0", 

184 "pa_version_under26p0", 

185]