Skip to content

Commit 5b40a64

Browse files
Add a pre-commit configuration to conform to new pydata conventions.
This patch also reformats code using the `ruff` code formatter.
1 parent 9fba33e commit 5b40a64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3863
-2496
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ doc/cdoc/build
8383
ehthumbs.db
8484
Icon?
8585
Thumbs.db
86+
87+
# Test generated files #
88+
########################
89+
.python-version

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: fix-byte-order-marker
9+
- id: destroyed-symlinks
10+
- id: fix-encoding-pragma
11+
args: ["--remove"]
12+
- id: mixed-line-ending
13+
- id: name-tests-test
14+
args: ["--pytest-test-first"]
15+
- id: pretty-format-json
16+
args: ["--autofix", "--no-ensure-ascii"]
17+
exclude: ".ipynb"
18+
19+
- repo: https://github.com/astral-sh/ruff-pre-commit
20+
rev: v0.7.3
21+
hooks:
22+
- id: ruff-format
23+
types_or: [ python, pyi, jupyter ]

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ the cheap trick way of doing it is:
104104
def arima(n, m):
105105
return ArimaModelType(n, m)
106106
and then in the factor type sniffing code detect these things and
107-
separate them out from "real" factors.
107+
separate them out from "real" factors.
108108

109109
* make sure that pickling works
110110
- And make sure that if we allow it at all, then it's sustainable!

doc/R-comparison.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Differences from R:
105105
# R:
106106
> qr(model.matrix(~ 1 + a:b))$rank
107107
[1] 4
108-
108+
109109
However, the matrix produced for this formula has 5 columns, meaning
110110
that it contains redundant overspecification:
111111

@@ -149,7 +149,7 @@ Differences from R:
149149
use a full-rank encoding for ``b``. Therefore, we *should* use a
150150
full-rank encoding for ``b``, and produce a model matrix with 6
151151
columns. But in fact, R gives us only 4:
152-
152+
153153
.. code-block:: rconsole
154154
155155
# R:

doc/_examples/example_lm.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import numpy as np
22
from patsy import dmatrices, build_design_matrices
33

4+
45
class LM(object):
56
"""An example ordinary least squares linear model class, analogous to R's
67
lm() function. Don't use this in real life, it isn't properly tested."""
8+
79
def __init__(self, formula_like, data={}):
810
y, x = dmatrices(formula_like, data, 1)
911
self.nobs = x.shape[0]
@@ -12,27 +14,27 @@ def __init__(self, formula_like, data={}):
1214
self._x_design_info = x.design_info
1315

1416
def __repr__(self):
15-
summary = ("Ordinary least-squares regression\n"
16-
" Model: %s ~ %s\n"
17-
" Regression (beta) coefficients:\n"
18-
% (self._y_design_info.describe(),
19-
self._x_design_info.describe()))
17+
summary = (
18+
"Ordinary least-squares regression\n"
19+
" Model: %s ~ %s\n"
20+
" Regression (beta) coefficients:\n"
21+
% (self._y_design_info.describe(), self._x_design_info.describe())
22+
)
2023
for name, value in zip(self._x_design_info.column_names, self.betas):
2124
summary += " %s: %0.3g\n" % (name, value[0])
2225
return summary
2326

2427
def predict(self, new_data):
25-
(new_x,) = build_design_matrices([self._x_design_info],
26-
new_data)
28+
(new_x,) = build_design_matrices([self._x_design_info], new_data)
2729
return np.dot(new_x, self.betas)
2830

2931
def loglik(self, new_data):
30-
(new_y, new_x) = build_design_matrices([self._y_design_info,
31-
self._x_design_info],
32-
new_data)
32+
(new_y, new_x) = build_design_matrices(
33+
[self._y_design_info, self._x_design_info], new_data
34+
)
3335
new_pred = np.dot(new_x, self.betas)
3436
sigma2 = self.rss / self.nobs
3537
# It'd be more elegant to use scipy.stats.norm.logpdf here, but adding
3638
# a dependency on scipy makes the docs build more complicated:
3739
Z = -0.5 * np.log(2 * np.pi * sigma2)
38-
return Z + -0.5 * (new_y - new_x) ** 2/sigma2
40+
return Z + -0.5 * (new_y - new_x) ** 2 / sigma2

doc/_examples/example_treatment.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import numpy as np
22

3+
34
class MyTreat(object):
45
def __init__(self, reference=0):
56
self.reference = reference
67

78
def code_with_intercept(self, levels):
8-
return ContrastMatrix(np.eye(len(levels)),
9-
["[My.%s]" % (level,) for level in levels])
9+
return ContrastMatrix(
10+
np.eye(len(levels)), ["[My.%s]" % (level,) for level in levels]
11+
)
1012

1113
def code_without_intercept(self, levels):
1214
eye = np.eye(len(levels) - 1)
13-
contrasts = np.vstack((eye[:self.reference, :],
14-
np.zeros((1, len(levels) - 1)),
15-
eye[self.reference:, :]))
16-
suffixes = ["[MyT.%s]" % (level,) for level in
17-
levels[:self.reference] + levels[self.reference + 1:]]
15+
contrasts = np.vstack(
16+
(
17+
eye[: self.reference, :],
18+
np.zeros((1, len(levels) - 1)),
19+
eye[self.reference :, :],
20+
)
21+
)
22+
suffixes = [
23+
"[MyT.%s]" % (level,)
24+
for level in levels[: self.reference] + levels[self.reference + 1 :]
25+
]
1826
return ContrastMatrix(contrasts, suffixes)

doc/_static/facebox.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@
7777
.facebox_overlayBG {
7878
background-color: #000;
7979
z-index: 99;
80-
}
80+
}

doc/_static/show-code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ function scrapeText(codebox){
2525
return newlines.join('\\n');
2626
}
2727

28-
$(document).ready(
28+
$(document).ready(
2929
function() {
3030
// grab all code boxes
3131
var ipythoncode = $(".highlight-ipython");
3232
$.each(ipythoncode, function() {
3333
var code = scrapeText($(this).text());
34-
// give them a facebox pop-up with plain text code
34+
// give them a facebox pop-up with plain text code
3535
$(this).append('<span style="text-align:right; display:block; margin-top:-10px; margin-left:10px; font-size:60%"><a href="javascript: jQuery.facebox(\'<textarea cols=80 rows=10 readonly style=margin:5px onmouseover=javascript:this.select();>'+htmlescape(htmlescape(code))+'</textarea>\');">View Code</a></span>');
3636
$(this,"textarea").select();
3737
});

doc/categorical-coding.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ As an example, here's a simplified version of the built-in
7878
:class:`Treatment` coding object:
7979

8080
.. literalinclude:: _examples/example_treatment.py
81-
81+
8282
.. ipython:: python
8383
:suppress:
8484

0 commit comments

Comments
 (0)