Skip to content

Commit 9ab70f9

Browse files
authored
Merge pull request #602 from bashtage/doc-fixes
DOC: Fix many aliases
2 parents 5aecf58 + d9b5ea9 commit 9ab70f9

35 files changed

+1100
-635
lines changed

doc/source/conf.py

+15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323

2424
# More warnings
2525
nitpicky = True
26+
nitpick_ignore = []
27+
28+
with open("nitpick-exceptions") as nitpick_ex:
29+
for line in nitpick_ex:
30+
if line.strip() == "" or line.startswith("#"):
31+
continue
32+
dtype, target = line.split(None, 1)
33+
target = target.strip()
34+
nitpick_ignore.append((dtype, target))
2635

2736
# The short X.Y version
2837
full_version = parse(linearmodels.__version__)
@@ -412,3 +421,9 @@
412421

413422
autosummary_generate = True
414423
autoclass_content = "class"
424+
425+
autodoc_type_aliases = {
426+
"ArrayLike": "linearmodels.typing.data.ArrayLike",
427+
"IntArray": "linearmodels.typing.data.IntArray",
428+
"Float64Array": "linearmodels.typing.data.Float64Array",
429+
}

doc/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ linearmodels
6767
system/index
6868
utility
6969
compatibility
70+
types
7071
plan
7172
contributing
7273
changes

doc/source/nitpick-exceptions

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# py:class ArrayLike
2+
py:class IVDataLike
3+
# py:class IntArray
4+
# py:class Float64Array
5+
6+

doc/source/types.rst

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Type Aliases
2+
============
3+
4+
.. module:: linearmodels.typing.data
5+
6+
.. automodule:: linearmodels.typing.data
7+
8+
.. autoclass::
9+
10+
ArrayLike
11+
Float64Array
12+
Int64Array
13+
Int32Array
14+
IntArray
15+
BoolArray
16+
AnyArray
17+
Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] # pragma: no cover
18+
19+
20+
.. module:: linearmodels.typing
21+
22+
.. automodule:: linearmodels.typing
23+
24+
.. autoclass::
25+
26+
Numeric
27+
OptionalNumeric

examples/panel_data-formats.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"source": [
5050
"orig_mi_data = data.set_index([\"fcode\", \"year\"])\n",
5151
"# Subset to the relevant columns and drop missing to avoid warnings\n",
52-
"mi_data = orig_mi_data[[\"lscrap\",\"hrsemp\"]]\n",
52+
"mi_data = orig_mi_data[[\"lscrap\", \"hrsemp\"]]\n",
5353
"mi_data = mi_data.dropna(axis=0, how=\"any\")\n",
5454
"\n",
5555
"print(mi_data.head())"

linearmodels/asset_pricing/covariance.py

+28-19
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44

55
from __future__ import annotations
66

7-
from numpy import empty, ndarray
7+
import numpy
8+
from numpy import empty
89
from numpy.linalg import inv
910

1011
from linearmodels.iv.covariance import (
1112
KERNEL_LOOKUP,
1213
cov_kernel,
1314
kernel_optimal_bandwidth,
1415
)
15-
from linearmodels.typing import Float64Array
16+
import linearmodels.typing.data
1617

1718

1819
class _HACMixin:
1920
def __init__(self, kernel: str, bandwidth: float | None) -> None:
2021
self._kernel: str | None = None
2122
self._bandwidth: float | None = None # pragma: no cover
22-
self._moments: ndarray = empty((0,)) # pragma: no cover
23+
self._moments: numpy.ndarray = empty((0,)) # pragma: no cover
2324
self._check_kernel(kernel)
2425
self._check_bandwidth(bandwidth)
2526

@@ -60,7 +61,9 @@ def _check_bandwidth(self, bandwidth: float | None) -> None:
6061
if bandwidth < 0:
6162
raise ValueError("bandwidth must be non-negative.")
6263

63-
def _kernel_cov(self, z: Float64Array) -> Float64Array:
64+
def _kernel_cov(
65+
self, z: linearmodels.typing.data.Float64Array
66+
) -> linearmodels.typing.data.Float64Array:
6467
nobs = z.shape[0]
6568
bw = self.bandwidth
6669
kernel = self._kernel
@@ -96,10 +99,10 @@ class HeteroskedasticCovariance:
9699

97100
def __init__(
98101
self,
99-
xe: Float64Array,
102+
xe: linearmodels.typing.data.Float64Array,
100103
*,
101-
jacobian: ndarray | None = None,
102-
inv_jacobian: ndarray | None = None,
104+
jacobian: numpy.ndarray | None = None,
105+
inv_jacobian: numpy.ndarray | None = None,
103106
center: bool = True,
104107
debiased: bool = False,
105108
df: int = 0,
@@ -131,7 +134,7 @@ def config(self) -> dict[str, str | float]:
131134
return {"type": self.__class__.__name__}
132135

133136
@property
134-
def s(self) -> Float64Array:
137+
def s(self) -> linearmodels.typing.data.Float64Array:
135138
"""
136139
Score/moment condition covariance
137140
@@ -149,7 +152,7 @@ def s(self) -> Float64Array:
149152
return (out + out.T) / 2
150153

151154
@property
152-
def jacobian(self) -> Float64Array:
155+
def jacobian(self) -> linearmodels.typing.data.Float64Array:
153156
"""The Jacobian"""
154157
if self._jac is None:
155158
assert self._inv_jac is not None
@@ -158,7 +161,7 @@ def jacobian(self) -> Float64Array:
158161
return self._jac
159162

160163
@property
161-
def inv_jacobian(self) -> Float64Array:
164+
def inv_jacobian(self) -> linearmodels.typing.data.Float64Array:
162165
"""Inverse Jacobian"""
163166
if self._inv_jac is None:
164167
assert self._jac is not None
@@ -172,7 +175,7 @@ def square(self) -> bool:
172175
return self._square
173176

174177
@property
175-
def cov(self) -> Float64Array:
178+
def cov(self) -> linearmodels.typing.data.Float64Array:
176179
"""
177180
Compute parameter covariance
178181
@@ -229,10 +232,10 @@ class KernelCovariance(HeteroskedasticCovariance, _HACMixin):
229232

230233
def __init__(
231234
self,
232-
xe: Float64Array,
235+
xe: linearmodels.typing.data.Float64Array,
233236
*,
234-
jacobian: ndarray | None = None,
235-
inv_jacobian: ndarray | None = None,
237+
jacobian: numpy.ndarray | None = None,
238+
inv_jacobian: numpy.ndarray | None = None,
236239
kernel: str | None = None,
237240
bandwidth: float | None = None,
238241
center: bool = True,
@@ -262,7 +265,7 @@ def config(self) -> dict[str, str | float]:
262265
return out
263266

264267
@property
265-
def s(self) -> Float64Array:
268+
def s(self) -> linearmodels.typing.data.Float64Array:
266269
"""
267270
Score/moment condition covariance
268271
@@ -289,11 +292,15 @@ class HeteroskedasticWeight:
289292
Flag indicating to center the moments when computing the weights
290293
"""
291294

292-
def __init__(self, moments: Float64Array, center: bool = True) -> None:
295+
def __init__(
296+
self, moments: linearmodels.typing.data.Float64Array, center: bool = True
297+
) -> None:
293298
self._moments = moments
294299
self._center = center
295300

296-
def w(self, moments: Float64Array) -> Float64Array:
301+
def w(
302+
self, moments: linearmodels.typing.data.Float64Array
303+
) -> linearmodels.typing.data.Float64Array:
297304
"""
298305
Score/moment condition weighting matrix
299306
@@ -335,7 +342,7 @@ class KernelWeight(HeteroskedasticWeight, _HACMixin):
335342

336343
def __init__(
337344
self,
338-
moments: Float64Array,
345+
moments: linearmodels.typing.data.Float64Array,
339346
center: bool = True,
340347
kernel: str | None = None,
341348
bandwidth: float | None = None,
@@ -344,7 +351,9 @@ def __init__(
344351
_HACMixin.__init__(self, kernel, bandwidth)
345352
super().__init__(moments, center=center)
346353

347-
def w(self, moments: Float64Array) -> Float64Array:
354+
def w(
355+
self, moments: linearmodels.typing.data.Float64Array
356+
) -> linearmodels.typing.data.Float64Array:
348357
"""
349358
Score/moment condition weighting matrix
350359

0 commit comments

Comments
 (0)