__init__.py 8.8 KB

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