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

65 statements  

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

1from __future__ import annotations 

2 

3__docformat__ = "restructuredtext" 

4 

5# Let users know if they're missing any of our hard dependencies 

6_hard_dependencies = ("numpy", "pytz", "dateutil") 

7_missing_dependencies = [] 

8 

9for _dependency in _hard_dependencies: 

10 try: 

11 __import__(_dependency) 

12 except ImportError as _e: 

13 _missing_dependencies.append(f"{_dependency}: {_e}") 

14 

15if _missing_dependencies: 15 ↛ 16line 15 didn't jump to line 16, because the condition on line 15 was never true

16 raise ImportError( 

17 "Unable to import required dependencies:\n" + "\n".join(_missing_dependencies) 

18 ) 

19del _hard_dependencies, _dependency, _missing_dependencies 

20 

21# numpy compat 

22from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401 

23 

24try: 

25 from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib 

26except ImportError as _err: # pragma: no cover 

27 _module = _err.name 

28 raise ImportError( 

29 f"C extension: {_module} not built. If you want to import " 

30 "pandas from the source directory, you may need to run " 

31 "'python setup.py build_ext --force' to build the C extensions first." 

32 ) from _err 

33else: 

34 del _tslib, _lib, _hashtable 

35 

36from pandas._config import ( 

37 get_option, 

38 set_option, 

39 reset_option, 

40 describe_option, 

41 option_context, 

42 options, 

43) 

44 

45# let init-time option registration happen 

46import pandas.core.config_init # pyright: ignore # noqa:F401 

47 

48from pandas.core.api import ( 

49 # dtype 

50 ArrowDtype, 

51 Int8Dtype, 

52 Int16Dtype, 

53 Int32Dtype, 

54 Int64Dtype, 

55 UInt8Dtype, 

56 UInt16Dtype, 

57 UInt32Dtype, 

58 UInt64Dtype, 

59 Float32Dtype, 

60 Float64Dtype, 

61 CategoricalDtype, 

62 PeriodDtype, 

63 IntervalDtype, 

64 DatetimeTZDtype, 

65 StringDtype, 

66 BooleanDtype, 

67 # missing 

68 NA, 

69 isna, 

70 isnull, 

71 notna, 

72 notnull, 

73 # indexes 

74 Index, 

75 CategoricalIndex, 

76 RangeIndex, 

77 MultiIndex, 

78 IntervalIndex, 

79 TimedeltaIndex, 

80 DatetimeIndex, 

81 PeriodIndex, 

82 IndexSlice, 

83 # tseries 

84 NaT, 

85 Period, 

86 period_range, 

87 Timedelta, 

88 timedelta_range, 

89 Timestamp, 

90 date_range, 

91 bdate_range, 

92 Interval, 

93 interval_range, 

94 DateOffset, 

95 # conversion 

96 to_numeric, 

97 to_datetime, 

98 to_timedelta, 

99 # misc 

100 Flags, 

101 Grouper, 

102 factorize, 

103 unique, 

104 value_counts, 

105 NamedAgg, 

106 array, 

107 Categorical, 

108 set_eng_float_format, 

109 Series, 

110 DataFrame, 

111) 

112 

113from pandas.core.arrays.sparse import SparseDtype 

114 

115from pandas.tseries.api import infer_freq 

116from pandas.tseries import offsets 

117 

118from pandas.core.computation.api import eval 

119 

120from pandas.core.reshape.api import ( 

121 concat, 

122 lreshape, 

123 melt, 

124 wide_to_long, 

125 merge, 

126 merge_asof, 

127 merge_ordered, 

128 crosstab, 

129 pivot, 

130 pivot_table, 

131 get_dummies, 

132 from_dummies, 

133 cut, 

134 qcut, 

135) 

136 

137from pandas import api, arrays, errors, io, plotting, tseries 

138from pandas import testing # noqa:PDF015 

139from pandas.util._print_versions import show_versions 

140 

141from pandas.io.api import ( 

142 # excel 

143 ExcelFile, 

144 ExcelWriter, 

145 read_excel, 

146 # parsers 

147 read_csv, 

148 read_fwf, 

149 read_table, 

150 # pickle 

151 read_pickle, 

152 to_pickle, 

153 # pytables 

154 HDFStore, 

155 read_hdf, 

156 # sql 

157 read_sql, 

158 read_sql_query, 

159 read_sql_table, 

160 # misc 

161 read_clipboard, 

162 read_parquet, 

163 read_orc, 

164 read_feather, 

165 read_gbq, 

166 read_html, 

167 read_xml, 

168 read_json, 

169 read_stata, 

170 read_sas, 

171 read_spss, 

172) 

173 

174from pandas.io.json import _json_normalize as json_normalize 

175 

176from pandas.util._tester import test 

177 

178# use the closest tagged version if possible 

179from pandas._version import get_versions 

180 

181v = get_versions() 

182__version__ = v.get("closest-tag", v["version"]) 

183__git_version__ = v.get("full-revisionid") 

184del get_versions, v 

185 

186# GH 27101 

187__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"] 

188 

189 

190def __dir__() -> list[str]: 

191 # GH43028 

192 # Int64Index etc. are deprecated, but we still want them to be available in the dir. 

193 # Remove in Pandas 2.0, when we remove Int64Index etc. from the code base. 

194 return list(globals().keys()) + __deprecated_num_index_names 

195 

196 

197def __getattr__(name): 

198 import warnings 

199 

200 if name in __deprecated_num_index_names: 

201 warnings.warn( 

202 f"pandas.{name} is deprecated " 

203 "and will be removed from pandas in a future version. " 

204 "Use pandas.Index with the appropriate dtype instead.", 

205 FutureWarning, 

206 stacklevel=2, 

207 ) 

208 from pandas.core.api import Float64Index, Int64Index, UInt64Index 

209 

210 return { 

211 "Float64Index": Float64Index, 

212 "Int64Index": Int64Index, 

213 "UInt64Index": UInt64Index, 

214 }[name] 

215 elif name == "datetime": 

216 warnings.warn( 

217 "The pandas.datetime class is deprecated " 

218 "and will be removed from pandas in a future version. " 

219 "Import from datetime module instead.", 

220 FutureWarning, 

221 stacklevel=2, 

222 ) 

223 

224 from datetime import datetime as dt 

225 

226 return dt 

227 

228 elif name == "np": 

229 

230 warnings.warn( 

231 "The pandas.np module is deprecated " 

232 "and will be removed from pandas in a future version. " 

233 "Import numpy directly instead.", 

234 FutureWarning, 

235 stacklevel=2, 

236 ) 

237 import numpy as np 

238 

239 return np 

240 

241 elif name in {"SparseSeries", "SparseDataFrame"}: 

242 warnings.warn( 

243 f"The {name} class is removed from pandas. Accessing it from " 

244 "the top-level namespace will also be removed in the next version.", 

245 FutureWarning, 

246 stacklevel=2, 

247 ) 

248 

249 return type(name, (), {}) 

250 

251 elif name == "SparseArray": 

252 

253 warnings.warn( 

254 "The pandas.SparseArray class is deprecated " 

255 "and will be removed from pandas in a future version. " 

256 "Use pandas.arrays.SparseArray instead.", 

257 FutureWarning, 

258 stacklevel=2, 

259 ) 

260 from pandas.core.arrays.sparse import SparseArray as _SparseArray 

261 

262 return _SparseArray 

263 

264 raise AttributeError(f"module 'pandas' has no attribute '{name}'") 

265 

266 

267# module level doc-string 

268__doc__ = """ 

269pandas - a powerful data analysis and manipulation library for Python 

270===================================================================== 

271 

272**pandas** is a Python package providing fast, flexible, and expressive data 

273structures designed to make working with "relational" or "labeled" data both 

274easy and intuitive. It aims to be the fundamental high-level building block for 

275doing practical, **real world** data analysis in Python. Additionally, it has 

276the broader goal of becoming **the most powerful and flexible open source data 

277analysis / manipulation tool available in any language**. It is already well on 

278its way toward this goal. 

279 

280Main Features 

281------------- 

282Here are just a few of the things that pandas does well: 

283 

284 - Easy handling of missing data in floating point as well as non-floating 

285 point data. 

286 - Size mutability: columns can be inserted and deleted from DataFrame and 

287 higher dimensional objects 

288 - Automatic and explicit data alignment: objects can be explicitly aligned 

289 to a set of labels, or the user can simply ignore the labels and let 

290 `Series`, `DataFrame`, etc. automatically align the data for you in 

291 computations. 

292 - Powerful, flexible group by functionality to perform split-apply-combine 

293 operations on data sets, for both aggregating and transforming data. 

294 - Make it easy to convert ragged, differently-indexed data in other Python 

295 and NumPy data structures into DataFrame objects. 

296 - Intelligent label-based slicing, fancy indexing, and subsetting of large 

297 data sets. 

298 - Intuitive merging and joining data sets. 

299 - Flexible reshaping and pivoting of data sets. 

300 - Hierarchical labeling of axes (possible to have multiple labels per tick). 

301 - Robust IO tools for loading data from flat files (CSV and delimited), 

302 Excel files, databases, and saving/loading data from the ultrafast HDF5 

303 format. 

304 - Time series-specific functionality: date range generation and frequency 

305 conversion, moving window statistics, date shifting and lagging. 

306""" 

307 

308# Use __all__ to let type checkers know what is part of the public API. 

309# Pandas is not (yet) a py.typed library: the public API is determined 

310# based on the documentation. 

311__all__ = [ 

312 "ArrowDtype", 

313 "BooleanDtype", 

314 "Categorical", 

315 "CategoricalDtype", 

316 "CategoricalIndex", 

317 "DataFrame", 

318 "DateOffset", 

319 "DatetimeIndex", 

320 "DatetimeTZDtype", 

321 "ExcelFile", 

322 "ExcelWriter", 

323 "Flags", 

324 "Float32Dtype", 

325 "Float64Dtype", 

326 "Grouper", 

327 "HDFStore", 

328 "Index", 

329 "IndexSlice", 

330 "Int16Dtype", 

331 "Int32Dtype", 

332 "Int64Dtype", 

333 "Int8Dtype", 

334 "Interval", 

335 "IntervalDtype", 

336 "IntervalIndex", 

337 "MultiIndex", 

338 "NA", 

339 "NaT", 

340 "NamedAgg", 

341 "Period", 

342 "PeriodDtype", 

343 "PeriodIndex", 

344 "RangeIndex", 

345 "Series", 

346 "SparseDtype", 

347 "StringDtype", 

348 "Timedelta", 

349 "TimedeltaIndex", 

350 "Timestamp", 

351 "UInt16Dtype", 

352 "UInt32Dtype", 

353 "UInt64Dtype", 

354 "UInt8Dtype", 

355 "api", 

356 "array", 

357 "arrays", 

358 "bdate_range", 

359 "concat", 

360 "crosstab", 

361 "cut", 

362 "date_range", 

363 "describe_option", 

364 "errors", 

365 "eval", 

366 "factorize", 

367 "get_dummies", 

368 "from_dummies", 

369 "get_option", 

370 "infer_freq", 

371 "interval_range", 

372 "io", 

373 "isna", 

374 "isnull", 

375 "json_normalize", 

376 "lreshape", 

377 "melt", 

378 "merge", 

379 "merge_asof", 

380 "merge_ordered", 

381 "notna", 

382 "notnull", 

383 "offsets", 

384 "option_context", 

385 "options", 

386 "period_range", 

387 "pivot", 

388 "pivot_table", 

389 "plotting", 

390 "qcut", 

391 "read_clipboard", 

392 "read_csv", 

393 "read_excel", 

394 "read_feather", 

395 "read_fwf", 

396 "read_gbq", 

397 "read_hdf", 

398 "read_html", 

399 "read_json", 

400 "read_orc", 

401 "read_parquet", 

402 "read_pickle", 

403 "read_sas", 

404 "read_spss", 

405 "read_sql", 

406 "read_sql_query", 

407 "read_sql_table", 

408 "read_stata", 

409 "read_table", 

410 "read_xml", 

411 "reset_option", 

412 "set_eng_float_format", 

413 "set_option", 

414 "show_versions", 

415 "test", 

416 "testing", 

417 "timedelta_range", 

418 "to_datetime", 

419 "to_numeric", 

420 "to_pickle", 

421 "to_timedelta", 

422 "tseries", 

423 "unique", 

424 "value_counts", 

425 "wide_to_long", 

426]