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

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

30 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 platform 

14import sys 

15from typing import TYPE_CHECKING 

16 

17from pandas.compat._constants import ( 

18 CHAINED_WARNING_DISABLED, 

19 IS64, 

20 ISMUSL, 

21 PY312, 

22 PY313, 

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_under17p0, 

34 pa_version_under18p0, 

35 pa_version_under19p0, 

36 pa_version_under20p0, 

37 pa_version_under21p0, 

38 pa_version_under22p0, 

39 pa_version_under23p0, 

40 pa_version_under25p0, 

41 pa_version_under26p0, 

42) 

43 

44if TYPE_CHECKING: 

45 from pandas._typing import F 

46 

47 

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

49 """ 

50 Bind the name/qualname attributes of the function. 

51 """ 

52 f.__name__ = name 

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

54 f.__module__ = cls.__module__ 

55 return f 

56 

57 

58def is_platform_little_endian() -> bool: 

59 """ 

60 Checking if the running platform is little endian. 

61 

62 Returns 

63 ------- 

64 bool 

65 True if the running platform is little endian. 

66 """ 

67 return sys.byteorder == "little" 

68 

69 

70def is_platform_windows() -> bool: 

71 """ 

72 Checking if the running platform is windows. 

73 

74 Returns 

75 ------- 

76 bool 

77 True if the running platform is windows. 

78 """ 

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

80 

81 

82def is_platform_linux() -> bool: 

83 """ 

84 Checking if the running platform is linux. 

85 

86 Returns 

87 ------- 

88 bool 

89 True if the running platform is linux. 

90 """ 

91 return sys.platform == "linux" 

92 

93 

94def is_platform_mac() -> bool: 

95 """ 

96 Checking if the running platform is mac. 

97 

98 Returns 

99 ------- 

100 bool 

101 True if the running platform is mac. 

102 """ 

103 return sys.platform == "darwin" 

104 

105 

106def is_platform_arm() -> bool: 

107 """ 

108 Checking if the running platform use ARM architecture. 

109 

110 Returns 

111 ------- 

112 bool 

113 True if the running platform uses ARM architecture. 

114 """ 

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

116 "armv" 

117 ) 

118 

119 

120def is_platform_power() -> bool: 

121 """ 

122 Checking if the running platform use Power architecture. 

123 

124 Returns 

125 ------- 

126 bool 

127 True if the running platform uses ARM architecture. 

128 """ 

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

130 

131 

132def is_platform_riscv64() -> bool: 

133 """ 

134 Checking if the running platform use riscv64 architecture. 

135 

136 Returns 

137 ------- 

138 bool 

139 True if the running platform uses riscv64 architecture. 

140 """ 

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

142 

143 

144__all__ = [ 

145 "CHAINED_WARNING_DISABLED", 

146 "HAS_PYARROW", 

147 "IS64", 

148 "ISMUSL", 

149 "PY312", 

150 "PY313", 

151 "PY314", 

152 "PY315", 

153 "PYARROW_INSTALLED", 

154 "PYARROW_MIN_VERSION", 

155 "PYPY", 

156 "WASM", 

157 "is_numpy_dev", 

158 "pa_version_under17p0", 

159 "pa_version_under18p0", 

160 "pa_version_under19p0", 

161 "pa_version_under20p0", 

162 "pa_version_under21p0", 

163 "pa_version_under22p0", 

164 "pa_version_under23p0", 

165 "pa_version_under25p0", 

166 "pa_version_under26p0", 

167]