Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/statsmodels/compat/numpy.py : 41%

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"""Compatibility functions for numpy versions in lib
3np_new_unique
4-------------
5Optionally provides the count of the number of occurrences of each
6unique element.
8Copied from Numpy source, under license:
10Copyright (c) 2005-2015, NumPy Developers.
11All rights reserved.
13Redistribution and use in source and binary forms, with or without
14modification, are permitted provided that the following conditions are
15met:
17* Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
20* Redistributions in binary form must reproduce the above
21 copyright notice, this list of conditions and the following
22 disclaimer in the documentation and/or other materials provided
23 with the distribution.
25* Neither the name of the NumPy Developers nor the names of any
26 contributors may be used to endorse or promote products derived
27 from this software without specific prior written permission.
29THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40"""
42from distutils.version import LooseVersion
44import numpy as np
46NP_LT_114 = LooseVersion(np.__version__) < LooseVersion('1.14')
48np_matrix_rank = np.linalg.matrix_rank
49np_new_unique = np.unique
52def recarray_select(recarray, fields):
53 """"
54 Work-around for changes in NumPy 1.13 that return views for recarray
55 multiple column selection
56 """
57 from pandas import DataFrame
58 fields = [fields] if not isinstance(fields, (tuple, list)) else fields
59 if len(fields) == len(recarray.dtype):
60 selection = recarray
61 else:
62 recarray = DataFrame.from_records(recarray)
63 selection = recarray[fields].to_records(index=False)
65 return selection
68def lstsq(a, b, rcond=None):
69 """
70 Shim that allows modern rcond setting with backward compat for NumPY
71 earlier than 1.14
72 """
73 if NP_LT_114 and rcond is None:
74 rcond = -1
75 return np.linalg.lstsq(a, b, rcond=rcond)