__init__.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. from __future__ import annotations
  2. # start delvewheel patch
  3. def _delvewheel_patch_1_12_0():
  4. import os
  5. if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'pandas.libs'))):
  6. os.add_dll_directory(libs_dir)
  7. _delvewheel_patch_1_12_0()
  8. del _delvewheel_patch_1_12_0
  9. # end delvewheel patch
  10. __docformat__ = "restructuredtext"
  11. # Let users know if they're missing any of our hard dependencies
  12. # except tzdata (see https://github.com/pandas-dev/pandas/issues/63264)
  13. _hard_dependencies = ("numpy", "dateutil")
  14. for _dependency in _hard_dependencies:
  15. try:
  16. __import__(_dependency)
  17. except ImportError as _e: # pragma: no cover
  18. raise ImportError(
  19. f"Unable to import required dependency {_dependency}. "
  20. "Please see the traceback for details."
  21. ) from _e
  22. del _hard_dependencies, _dependency
  23. try:
  24. # numpy compat
  25. from pandas.compat import (
  26. is_numpy_dev as _is_numpy_dev, # pyright: ignore[reportUnusedImport] # noqa: F401
  27. )
  28. except ImportError as _err: # pragma: no cover
  29. _module = _err.name
  30. raise ImportError(
  31. f"C extension: {_module} not built. If you want to import "
  32. "pandas from the source directory, you may need to run "
  33. "'python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true' "
  34. "to build the C extensions first."
  35. ) from _err
  36. from pandas._config import (
  37. get_option,
  38. set_option,
  39. reset_option,
  40. describe_option,
  41. option_context,
  42. options,
  43. )
  44. # let init-time option registration happen
  45. import pandas.core.config_init # pyright: ignore[reportUnusedImport] # noqa: F401
  46. from pandas.core.api import (
  47. # dtype
  48. ArrowDtype,
  49. Int8Dtype,
  50. Int16Dtype,
  51. Int32Dtype,
  52. Int64Dtype,
  53. UInt8Dtype,
  54. UInt16Dtype,
  55. UInt32Dtype,
  56. UInt64Dtype,
  57. Float32Dtype,
  58. Float64Dtype,
  59. CategoricalDtype,
  60. PeriodDtype,
  61. IntervalDtype,
  62. DatetimeTZDtype,
  63. StringDtype,
  64. BooleanDtype,
  65. # missing
  66. NA,
  67. isna,
  68. isnull,
  69. notna,
  70. notnull,
  71. # indexes
  72. Index,
  73. CategoricalIndex,
  74. RangeIndex,
  75. MultiIndex,
  76. IntervalIndex,
  77. TimedeltaIndex,
  78. DatetimeIndex,
  79. PeriodIndex,
  80. IndexSlice,
  81. # tseries
  82. NaT,
  83. Period,
  84. period_range,
  85. Timedelta,
  86. timedelta_range,
  87. Timestamp,
  88. date_range,
  89. bdate_range,
  90. Interval,
  91. interval_range,
  92. DateOffset,
  93. # conversion
  94. to_numeric,
  95. to_datetime,
  96. to_timedelta,
  97. # misc
  98. Flags,
  99. Grouper,
  100. factorize,
  101. unique,
  102. NamedAgg,
  103. array,
  104. Categorical,
  105. set_eng_float_format,
  106. Series,
  107. DataFrame,
  108. )
  109. from pandas.core.col import col
  110. from pandas.core.dtypes.dtypes import SparseDtype
  111. from pandas.tseries.api import infer_freq
  112. from pandas.tseries import offsets
  113. from pandas.core.computation.api import eval
  114. from pandas.core.reshape.api import (
  115. concat,
  116. lreshape,
  117. melt,
  118. wide_to_long,
  119. merge,
  120. merge_asof,
  121. merge_ordered,
  122. crosstab,
  123. pivot,
  124. pivot_table,
  125. get_dummies,
  126. from_dummies,
  127. cut,
  128. qcut,
  129. )
  130. from pandas import api, arrays, errors, io, plotting, tseries
  131. from pandas import testing
  132. from pandas.util._print_versions import show_versions
  133. from pandas.io.api import (
  134. # excel
  135. ExcelFile,
  136. ExcelWriter,
  137. read_excel,
  138. # parsers
  139. read_csv,
  140. read_fwf,
  141. read_table,
  142. # pickle
  143. read_pickle,
  144. to_pickle,
  145. # pytables
  146. HDFStore,
  147. read_hdf,
  148. # sql
  149. read_sql,
  150. read_sql_query,
  151. read_sql_table,
  152. # misc
  153. read_clipboard,
  154. read_parquet,
  155. read_orc,
  156. read_feather,
  157. read_html,
  158. read_xml,
  159. read_json,
  160. read_stata,
  161. read_sas,
  162. read_spss,
  163. read_iceberg,
  164. )
  165. from pandas.io.json._normalize import json_normalize
  166. from pandas.util._tester import test
  167. # use the closest tagged version if possible
  168. _built_with_meson = False
  169. try:
  170. from pandas._version_meson import ( # pyright: ignore [reportMissingImports]
  171. __version__,
  172. __git_version__,
  173. )
  174. _built_with_meson = True
  175. except ImportError:
  176. from pandas._version import get_versions
  177. v = get_versions()
  178. __version__ = v.get("closest-tag", v["version"])
  179. __git_version__ = v.get("full-revisionid")
  180. del get_versions, v
  181. # module level doc-string
  182. __doc__ = """
  183. pandas - a powerful data analysis and manipulation library for Python
  184. =====================================================================
  185. **pandas** is a Python package providing fast, flexible, and expressive data
  186. structures designed to make working with "relational" or "labeled" data both
  187. easy and intuitive. It aims to be the fundamental high-level building block for
  188. doing practical, **real world** data analysis in Python. Additionally, it has
  189. the broader goal of becoming **the most powerful and flexible open source data
  190. analysis / manipulation tool available in any language**. It is already well on
  191. its way toward this goal.
  192. Main Features
  193. -------------
  194. Here are just a few of the things that pandas does well:
  195. - Easy handling of missing data in floating point as well as non-floating
  196. point data.
  197. - Size mutability: columns can be inserted and deleted from DataFrame and
  198. higher dimensional objects
  199. - Automatic and explicit data alignment: objects can be explicitly aligned
  200. to a set of labels, or the user can simply ignore the labels and let
  201. `Series`, `DataFrame`, etc. automatically align the data for you in
  202. computations.
  203. - Powerful, flexible group by functionality to perform split-apply-combine
  204. operations on data sets, for both aggregating and transforming data.
  205. - Make it easy to convert ragged, differently-indexed data in other Python
  206. and NumPy data structures into DataFrame objects.
  207. - Intelligent label-based slicing, fancy indexing, and subsetting of large
  208. data sets.
  209. - Intuitive merging and joining data sets.
  210. - Flexible reshaping and pivoting of data sets.
  211. - Hierarchical labeling of axes (possible to have multiple labels per tick).
  212. - Robust IO tools for loading data from flat files (CSV and delimited),
  213. Excel files, databases, and saving/loading data from the ultrafast HDF5
  214. format.
  215. - Time series-specific functionality: date range generation and frequency
  216. conversion, moving window statistics, date shifting and lagging.
  217. """
  218. # Use __all__ to let type checkers know what is part of the public API.
  219. # Pandas is not (yet) a py.typed library: the public API is determined
  220. # based on the documentation.
  221. __all__ = [
  222. "NA",
  223. "ArrowDtype",
  224. "BooleanDtype",
  225. "Categorical",
  226. "CategoricalDtype",
  227. "CategoricalIndex",
  228. "DataFrame",
  229. "DateOffset",
  230. "DatetimeIndex",
  231. "DatetimeTZDtype",
  232. "ExcelFile",
  233. "ExcelWriter",
  234. "Flags",
  235. "Float32Dtype",
  236. "Float64Dtype",
  237. "Grouper",
  238. "HDFStore",
  239. "Index",
  240. "IndexSlice",
  241. "Int8Dtype",
  242. "Int16Dtype",
  243. "Int32Dtype",
  244. "Int64Dtype",
  245. "Interval",
  246. "IntervalDtype",
  247. "IntervalIndex",
  248. "MultiIndex",
  249. "NaT",
  250. "NamedAgg",
  251. "Period",
  252. "PeriodDtype",
  253. "PeriodIndex",
  254. "RangeIndex",
  255. "Series",
  256. "SparseDtype",
  257. "StringDtype",
  258. "Timedelta",
  259. "TimedeltaIndex",
  260. "Timestamp",
  261. "UInt8Dtype",
  262. "UInt16Dtype",
  263. "UInt32Dtype",
  264. "UInt64Dtype",
  265. "api",
  266. "array",
  267. "arrays",
  268. "bdate_range",
  269. "col",
  270. "concat",
  271. "crosstab",
  272. "cut",
  273. "date_range",
  274. "describe_option",
  275. "errors",
  276. "eval",
  277. "factorize",
  278. "from_dummies",
  279. "get_dummies",
  280. "get_option",
  281. "infer_freq",
  282. "interval_range",
  283. "io",
  284. "isna",
  285. "isnull",
  286. "json_normalize",
  287. "lreshape",
  288. "melt",
  289. "merge",
  290. "merge_asof",
  291. "merge_ordered",
  292. "notna",
  293. "notnull",
  294. "offsets",
  295. "option_context",
  296. "options",
  297. "period_range",
  298. "pivot",
  299. "pivot_table",
  300. "plotting",
  301. "qcut",
  302. "read_clipboard",
  303. "read_csv",
  304. "read_excel",
  305. "read_feather",
  306. "read_fwf",
  307. "read_hdf",
  308. "read_html",
  309. "read_iceberg",
  310. "read_json",
  311. "read_orc",
  312. "read_parquet",
  313. "read_pickle",
  314. "read_sas",
  315. "read_spss",
  316. "read_sql",
  317. "read_sql_query",
  318. "read_sql_table",
  319. "read_stata",
  320. "read_table",
  321. "read_xml",
  322. "reset_option",
  323. "set_eng_float_format",
  324. "set_option",
  325. "show_versions",
  326. "test",
  327. "testing",
  328. "timedelta_range",
  329. "to_datetime",
  330. "to_numeric",
  331. "to_pickle",
  332. "to_timedelta",
  333. "tseries",
  334. "unique",
  335. "wide_to_long",
  336. ]