Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/__init__.py : 57%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# flake8: noqa
3__docformat__ = "restructuredtext"
5# Let users know if they're missing any of our hard dependencies
6hard_dependencies = ("numpy", "pytz", "dateutil")
7missing_dependencies = []
9for dependency in hard_dependencies:
10 try:
11 __import__(dependency)
12 except ImportError as e:
13 missing_dependencies.append(f"{dependency}: {e}")
15if missing_dependencies:
16 raise ImportError(
17 "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
18 )
19del hard_dependencies, dependency, missing_dependencies
21# numpy compat
22from pandas.compat.numpy import (
23 _np_version_under1p14,
24 _np_version_under1p15,
25 _np_version_under1p16,
26 _np_version_under1p17,
27 _np_version_under1p18,
28 _is_numpy_dev,
29)
31try:
32 from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
33except ImportError as e: # pragma: no cover
34 # hack but overkill to use re
35 module = str(e).replace("cannot import name ", "")
36 raise ImportError(
37 f"C extension: {module} not built. If you want to import "
38 "pandas from the source directory, you may need to run "
39 "'python setup.py build_ext --inplace --force' to build "
40 "the C extensions first."
41 )
43from pandas._config import (
44 get_option,
45 set_option,
46 reset_option,
47 describe_option,
48 option_context,
49 options,
50)
52# let init-time option registration happen
53import pandas.core.config_init
55from pandas.core.api import (
56 # dtype
57 Int8Dtype,
58 Int16Dtype,
59 Int32Dtype,
60 Int64Dtype,
61 UInt8Dtype,
62 UInt16Dtype,
63 UInt32Dtype,
64 UInt64Dtype,
65 CategoricalDtype,
66 PeriodDtype,
67 IntervalDtype,
68 DatetimeTZDtype,
69 StringDtype,
70 BooleanDtype,
71 # missing
72 NA,
73 isna,
74 isnull,
75 notna,
76 notnull,
77 # indexes
78 Index,
79 CategoricalIndex,
80 Int64Index,
81 UInt64Index,
82 RangeIndex,
83 Float64Index,
84 MultiIndex,
85 IntervalIndex,
86 TimedeltaIndex,
87 DatetimeIndex,
88 PeriodIndex,
89 IndexSlice,
90 # tseries
91 NaT,
92 Period,
93 period_range,
94 Timedelta,
95 timedelta_range,
96 Timestamp,
97 date_range,
98 bdate_range,
99 Interval,
100 interval_range,
101 DateOffset,
102 # conversion
103 to_numeric,
104 to_datetime,
105 to_timedelta,
106 # misc
107 Grouper,
108 factorize,
109 unique,
110 value_counts,
111 NamedAgg,
112 array,
113 Categorical,
114 set_eng_float_format,
115 Series,
116 DataFrame,
117)
119from pandas.core.arrays.sparse import SparseDtype
121from pandas.tseries.api import infer_freq
122from pandas.tseries import offsets
124from pandas.core.computation.api import eval
126from pandas.core.reshape.api import (
127 concat,
128 lreshape,
129 melt,
130 wide_to_long,
131 merge,
132 merge_asof,
133 merge_ordered,
134 crosstab,
135 pivot,
136 pivot_table,
137 get_dummies,
138 cut,
139 qcut,
140)
142import pandas.api
143from pandas.util._print_versions import show_versions
145from pandas.io.api import (
146 # excel
147 ExcelFile,
148 ExcelWriter,
149 read_excel,
150 # parsers
151 read_csv,
152 read_fwf,
153 read_table,
154 # pickle
155 read_pickle,
156 to_pickle,
157 # pytables
158 HDFStore,
159 read_hdf,
160 # sql
161 read_sql,
162 read_sql_query,
163 read_sql_table,
164 # misc
165 read_clipboard,
166 read_parquet,
167 read_orc,
168 read_feather,
169 read_gbq,
170 read_html,
171 read_json,
172 read_stata,
173 read_sas,
174 read_spss,
175)
177from pandas.io.json import _json_normalize as json_normalize
179from pandas.util._tester import test
180import pandas.testing
181import pandas.arrays
183# use the closest tagged version if possible
184from ._version import get_versions
186v = get_versions()
187__version__ = v.get("closest-tag", v["version"])
188__git_version__ = v.get("full-revisionid")
189del get_versions, v
191# GH 27101
192# TODO: remove Panel compat in 1.0
193if pandas.compat.PY37:
195 def __getattr__(name):
196 import warnings
198 if name == "Panel":
200 warnings.warn(
201 "The Panel class is removed from pandas. Accessing it "
202 "from the top-level namespace will also be removed in "
203 "the next version",
204 FutureWarning,
205 stacklevel=2,
206 )
208 class Panel:
209 pass
211 return Panel
213 elif name == "datetime":
214 warnings.warn(
215 "The pandas.datetime class is deprecated "
216 "and will be removed from pandas in a future version. "
217 "Import from datetime module instead.",
218 FutureWarning,
219 stacklevel=2,
220 )
222 from datetime import datetime as dt
224 return dt
226 elif name == "np":
228 warnings.warn(
229 "The pandas.np module is deprecated "
230 "and will be removed from pandas in a future version. "
231 "Import numpy directly instead",
232 FutureWarning,
233 stacklevel=2,
234 )
235 import numpy as np
237 return np
239 elif name in {"SparseSeries", "SparseDataFrame"}:
240 warnings.warn(
241 f"The {name} class is removed from pandas. Accessing it from "
242 "the top-level namespace will also be removed in the next "
243 "version",
244 FutureWarning,
245 stacklevel=2,
246 )
248 return type(name, (), {})
250 elif name == "SparseArray":
252 warnings.warn(
253 "The pandas.SparseArray class is deprecated "
254 "and will be removed from pandas in a future version. "
255 "Use pandas.arrays.SparseArray instead.",
256 FutureWarning,
257 stacklevel=2,
258 )
259 from pandas.core.arrays.sparse import SparseArray as _SparseArray
261 return _SparseArray
263 raise AttributeError(f"module 'pandas' has no attribute '{name}'")
266else:
268 class Panel:
269 pass
271 class SparseDataFrame:
272 pass
274 class SparseSeries:
275 pass
277 class __numpy:
278 def __init__(self):
279 import numpy as np
280 import warnings
282 self.np = np
283 self.warnings = warnings
285 def __getattr__(self, item):
286 self.warnings.warn(
287 "The pandas.np module is deprecated "
288 "and will be removed from pandas in a future version. "
289 "Import numpy directly instead",
290 FutureWarning,
291 stacklevel=2,
292 )
294 try:
295 return getattr(self.np, item)
296 except AttributeError:
297 raise AttributeError(f"module numpy has no attribute {item}")
299 np = __numpy()
301 class __Datetime(type):
303 from datetime import datetime as dt
305 datetime = dt
307 def __getattr__(cls, item):
308 cls.emit_warning()
310 try:
311 return getattr(cls.datetime, item)
312 except AttributeError:
313 raise AttributeError(f"module datetime has no attribute {item}")
315 def __instancecheck__(cls, other):
316 return isinstance(other, cls.datetime)
318 class __DatetimeSub(metaclass=__Datetime):
319 def emit_warning(dummy=0):
320 import warnings
322 warnings.warn(
323 "The pandas.datetime class is deprecated "
324 "and will be removed from pandas in a future version. "
325 "Import from datetime instead.",
326 FutureWarning,
327 stacklevel=3,
328 )
330 def __new__(cls, *args, **kwargs):
331 cls.emit_warning()
332 from datetime import datetime as dt
334 return dt(*args, **kwargs)
336 datetime = __DatetimeSub
338 class __SparseArray(type):
340 from pandas.core.arrays.sparse import SparseArray as sa
342 SparseArray = sa
344 def __instancecheck__(cls, other):
345 return isinstance(other, cls.SparseArray)
347 class __SparseArraySub(metaclass=__SparseArray):
348 def emit_warning(dummy=0):
349 import warnings
351 warnings.warn(
352 "The pandas.SparseArray class is deprecated "
353 "and will be removed from pandas in a future version. "
354 "Use pandas.arrays.SparseArray instead.",
355 FutureWarning,
356 stacklevel=3,
357 )
359 def __new__(cls, *args, **kwargs):
360 cls.emit_warning()
361 from pandas.core.arrays.sparse import SparseArray as sa
363 return sa(*args, **kwargs)
365 SparseArray = __SparseArraySub
368# module level doc-string
369__doc__ = """
370pandas - a powerful data analysis and manipulation library for Python
371=====================================================================
373**pandas** is a Python package providing fast, flexible, and expressive data
374structures designed to make working with "relational" or "labeled" data both
375easy and intuitive. It aims to be the fundamental high-level building block for
376doing practical, **real world** data analysis in Python. Additionally, it has
377the broader goal of becoming **the most powerful and flexible open source data
378analysis / manipulation tool available in any language**. It is already well on
379its way toward this goal.
381Main Features
382-------------
383Here are just a few of the things that pandas does well:
385 - Easy handling of missing data in floating point as well as non-floating
386 point data.
387 - Size mutability: columns can be inserted and deleted from DataFrame and
388 higher dimensional objects
389 - Automatic and explicit data alignment: objects can be explicitly aligned
390 to a set of labels, or the user can simply ignore the labels and let
391 `Series`, `DataFrame`, etc. automatically align the data for you in
392 computations.
393 - Powerful, flexible group by functionality to perform split-apply-combine
394 operations on data sets, for both aggregating and transforming data.
395 - Make it easy to convert ragged, differently-indexed data in other Python
396 and NumPy data structures into DataFrame objects.
397 - Intelligent label-based slicing, fancy indexing, and subsetting of large
398 data sets.
399 - Intuitive merging and joining data sets.
400 - Flexible reshaping and pivoting of data sets.
401 - Hierarchical labeling of axes (possible to have multiple labels per tick).
402 - Robust IO tools for loading data from flat files (CSV and delimited),
403 Excel files, databases, and saving/loading data from the ultrafast HDF5
404 format.
405 - Time series-specific functionality: date range generation and frequency
406 conversion, moving window statistics, date shifting and lagging.
407"""