forked from pydata/patsy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
140 lines (94 loc) · 3.56 KB
/
__init__.py
File metadata and controls
140 lines (94 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# This file is part of Patsy
# Copyright (C) 2011-2013 Nathaniel Smith <njs@pobox.com>
# See file LICENSE.txt for license information.
"""patsy is a Python package for describing statistical models and building
design matrices. It is closely inspired by the 'formula' mini-language used in
R and S."""
from patsy.version import __version__
# Do this first, to make it easy to check for warnings while testing:
import os
if os.environ.get("PATSY_FORCE_NO_WARNINGS"):
import warnings
warnings.filterwarnings("error", module="^patsy")
warnings.filterwarnings(
"ignore",
"is_categorical_dtype is deprecated",
DeprecationWarning,
module="^patsy",
)
del warnings
del os
import patsy.origin
class PatsyError(Exception):
"""This is the main error type raised by Patsy functions.
In addition to the usual Python exception features, you can pass a second
argument to this function specifying the origin of the error; this is
included in any error message, and used to help the user locate errors
arising from malformed formulas. This second argument should be an
:class:`Origin` object, or else an arbitrary object with a ``.origin``
attribute. (If it is neither of these things, then it will simply be
ignored.)
For ordinary display to the user with default formatting, use
``str(exc)``. If you want to do something cleverer, you can use the
``.message`` and ``.origin`` attributes directly. (The latter may be
None.)
"""
def __init__(self, message, origin=None):
Exception.__init__(self, message)
self.message = message
self.origin = None
self.set_origin(origin)
def __str__(self):
if self.origin is None:
return self.message
else:
return "%s\n%s" % (self.message, self.origin.caretize(indent=4))
def set_origin(self, origin):
# This is useful to modify an exception to add origin information as
# it "passes by", without losing traceback information. (In Python 3
# we can use the built-in exception wrapping stuff, but it will be
# some time before we can count on that...)
if self.origin is None:
if hasattr(origin, "origin"):
origin = origin.origin
if not isinstance(origin, patsy.origin.Origin):
origin = None
self.origin = origin
__all__ = ["PatsyError"]
# We make a rich API available for explicit use. To see what exactly is
# exported, check each module's __all__, or import this module and look at its
# __all__.
def _reexport(mod):
__all__.extend(mod.__all__)
for var in mod.__all__:
globals()[var] = getattr(mod, var)
# This used to have less copy-paste, but explicit import statements make
# packaging tools like py2exe and py2app happier. Sigh.
import patsy.highlevel
_reexport(patsy.highlevel)
import patsy.build
_reexport(patsy.build)
import patsy.constraint
_reexport(patsy.constraint)
import patsy.contrasts
_reexport(patsy.contrasts)
import patsy.desc
_reexport(patsy.desc)
import patsy.design_info
_reexport(patsy.design_info)
import patsy.eval
_reexport(patsy.eval)
import patsy.origin
_reexport(patsy.origin)
import patsy.state
_reexport(patsy.state)
import patsy.user_util
_reexport(patsy.user_util)
import patsy.missing
_reexport(patsy.missing)
import patsy.splines
_reexport(patsy.splines)
import patsy.mgcv_cubic_splines
_reexport(patsy.mgcv_cubic_splines)
# XX FIXME: we aren't exporting any of the explicit parsing interface
# yet. Need to figure out how to do that.