Skip to content

Commit

Permalink
DOC: Fix many aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtage committed Jun 7, 2024
1 parent 9288df3 commit 09b150f
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 109 deletions.
9 changes: 9 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@

# More warnings
nitpicky = True
nitpick_ignore = []

for line in open('nitpick-exceptions'):

Check warning

Code scanning / CodeQL

File is not always closed Warning documentation

File is opened but is not closed.
if line.strip() == "" or line.startswith("#"):
continue
dtype, target = line.split(None, 1)
target = target.strip()
nitpick_ignore.append((dtype, target))


# The short X.Y version
full_version = parse(linearmodels.__version__)
Expand Down
5 changes: 5 additions & 0 deletions doc/source/nitpick-exceptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
py:class ArrayLike
py:class IVDataLike
py:class Float64Array
py:class IntArray

13 changes: 7 additions & 6 deletions linearmodels/asset_pricing/covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from __future__ import annotations

from numpy import empty, ndarray
import numpy
from numpy import empty
from numpy.linalg import inv

from linearmodels.iv.covariance import (
Expand All @@ -19,7 +20,7 @@ class _HACMixin:
def __init__(self, kernel: str, bandwidth: float | None) -> None:
self._kernel: str | None = None
self._bandwidth: float | None = None # pragma: no cover
self._moments: ndarray = empty((0,)) # pragma: no cover
self._moments: numpy.ndarray = empty((0,)) # pragma: no cover
self._check_kernel(kernel)
self._check_bandwidth(bandwidth)

Expand Down Expand Up @@ -98,8 +99,8 @@ def __init__(
self,
xe: Float64Array,
*,
jacobian: ndarray | None = None,
inv_jacobian: ndarray | None = None,
jacobian: numpy.ndarray | None = None,
inv_jacobian: numpy.ndarray | None = None,
center: bool = True,
debiased: bool = False,
df: int = 0,
Expand Down Expand Up @@ -231,8 +232,8 @@ def __init__(
self,
xe: Float64Array,
*,
jacobian: ndarray | None = None,
inv_jacobian: ndarray | None = None,
jacobian: numpy.ndarray | None = None,
inv_jacobian: numpy.ndarray | None = None,
kernel: str | None = None,
bandwidth: float | None = None,
center: bool = True,
Expand Down
17 changes: 11 additions & 6 deletions linearmodels/asset_pricing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from formulaic.materializers.types import NAAction
import numpy as np
from numpy.linalg import lstsq
import pandas
from pandas import DataFrame
from scipy.optimize import minimize

Expand Down Expand Up @@ -134,7 +135,7 @@ def formula(self, value: str | None) -> None:

@staticmethod
def _prepare_data_from_formula(
formula: str, data: DataFrame, portfolios: DataFrame | None
formula: str, data: pandas.DataFrame, portfolios: pandas.DataFrame | None
) -> tuple[DataFrame, DataFrame, str]:
orig_formula = formula
na_action = NAAction("raise")
Expand Down Expand Up @@ -203,7 +204,11 @@ def __init__(self, portfolios: IVDataLike, factors: IVDataLike):

@classmethod
def from_formula(
cls, formula: str, data: DataFrame, *, portfolios: DataFrame | None = None
cls,
formula: str,
data: pandas.DataFrame,
*,
portfolios: pandas.DataFrame | None = None,
) -> TradedFactorModel:
"""
Parameters
Expand Down Expand Up @@ -517,9 +522,9 @@ def __init__(
def from_formula(
cls,
formula: str,
data: DataFrame,
data: pandas.DataFrame,
*,
portfolios: DataFrame | None = None,
portfolios: pandas.DataFrame | None = None,
risk_free: bool = False,
sigma: ArrayLike | None = None,
) -> LinearFactorModel:
Expand Down Expand Up @@ -818,9 +823,9 @@ def __init__(
def from_formula(
cls,
formula: str,
data: DataFrame,
data: pandas.DataFrame,
*,
portfolios: DataFrame | None = None,
portfolios: pandas.DataFrame | None = None,
risk_free: bool = False,
) -> LinearFactorModelGMM:
"""
Expand Down
6 changes: 4 additions & 2 deletions linearmodels/iv/_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from formulaic.formula import Formula
from formulaic.materializers.types import NAAction as fNAAction
from formulaic.utils.context import capture_context
import numpy

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'numpy' is not used.
import numpy as np
import pandas
from pandas import DataFrame

from linearmodels.typing import Float64Array
Expand Down Expand Up @@ -91,7 +93,7 @@ class IVFormulaParser:
def __init__(
self,
formula: str,
data: DataFrame,
data: pandas.DataFrame,
eval_env: int = 2,
context: Mapping[str, Any] | None = None,
):
Expand Down Expand Up @@ -222,5 +224,5 @@ def components(self) -> dict[str, str]:
return self._components

@staticmethod
def _empty_check(arr: DataFrame) -> DataFrame | None:
def _empty_check(arr: pandas.DataFrame) -> DataFrame | None:
return None if arr.shape[1] == 0 else arr
6 changes: 4 additions & 2 deletions linearmodels/iv/absorbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from numpy import (
any as npany,
arange,
array,
asarray,
ascontiguousarray,
average,
Expand All @@ -31,6 +30,7 @@
zeros,
)
from numpy.linalg import lstsq
import pandas
from pandas import Categorical, CategoricalDtype, DataFrame, Series
import scipy.sparse as sp
from scipy.sparse.linalg import lsmr
Expand Down Expand Up @@ -211,7 +211,9 @@ def category_product(cats: AnyPandas) -> Series:
return Series(Categorical(codes), index=cats.index)


def category_interaction(cat: Series, precondition: bool = True) -> sp.csc_matrix:
def category_interaction(
cat: pandas.Series, precondition: bool = True
) -> sp.csc_matrix:
"""
Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion linearmodels/iv/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, Union

import numpy as np
import pandas
import pandas as pd
from pandas.api.types import is_numeric_dtype, is_string_dtype

Expand All @@ -26,7 +27,7 @@ def convert_columns(s: pd.Series, drop_first: bool) -> AnyPandas:
return s


def expand_categoricals(x: pd.DataFrame, drop_first: bool) -> pd.DataFrame:
def expand_categoricals(x: pandas.DataFrame, drop_first: bool) -> pd.DataFrame:
if x.shape[1] == 0:
return x
return pd.concat(
Expand Down
15 changes: 9 additions & 6 deletions linearmodels/iv/gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from typing import Any

from numpy import asarray, ndarray, unique
import numpy
from numpy import asarray, unique
from numpy.linalg import inv

from linearmodels.iv.covariance import (
Expand Down Expand Up @@ -75,7 +76,7 @@ def weight_matrix(
return w

@property
def config(self) -> dict[str, str | bool | ndarray | int | None]:
def config(self) -> dict[str, str | bool | numpy.ndarray | int | None]:
"""
Weight estimator configuration
Expand Down Expand Up @@ -239,7 +240,7 @@ def weight_matrix(
return s

@property
def config(self) -> dict[str, str | bool | ndarray | int | None]:
def config(self) -> dict[str, str | bool | numpy.ndarray | int | None]:
"""
Weight estimator configuration
Expand Down Expand Up @@ -324,7 +325,7 @@ def weight_matrix(
return s

@property
def config(self) -> dict[str, str | bool | ndarray | int | None]:
def config(self) -> dict[str, str | bool | numpy.ndarray | int | None]:
"""
Weight estimator configuration
Expand Down Expand Up @@ -466,7 +467,9 @@ def cov(self) -> Float64Array:
return (c + c.T) / 2

@property
def config(self) -> dict[str, str | bool | ndarray | int | None]:
conf: dict[str, str | bool | ndarray | int | None] = {"debiased": self.debiased}
def config(self) -> dict[str, str | bool | numpy.ndarray | int | None]:
conf: dict[str, str | bool | numpy.ndarray | int | None] = {
"debiased": self.debiased
}
conf.update(self._cov_config)
return conf
17 changes: 9 additions & 8 deletions linearmodels/iv/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
squeeze,
)
from numpy.linalg import eigvalsh, inv, matrix_rank, pinv
import pandas
from pandas import DataFrame, Series, concat
from scipy.optimize import minimize

Expand Down Expand Up @@ -243,7 +244,7 @@ def predict(
*,
exog: IVDataLike | None = None,
endog: IVDataLike | None = None,
data: DataFrame | None = None,
data: pandas.DataFrame | None = None,
eval_env: int = 4,
) -> DataFrame:
"""
Expand Down Expand Up @@ -776,7 +777,7 @@ def __init__(
@staticmethod
def from_formula(
formula: str,
data: DataFrame,
data: pandas.DataFrame,
*,
weights: IVDataLike | None = None,
fuller: float = 0,
Expand Down Expand Up @@ -889,7 +890,7 @@ def __init__(

@staticmethod
def from_formula(
formula: str, data: DataFrame, *, weights: IVDataLike | None = None
formula: str, data: pandas.DataFrame, *, weights: IVDataLike | None = None
) -> IV2SLS:
"""
Parameters
Expand Down Expand Up @@ -1106,7 +1107,7 @@ def __init__(
@staticmethod
def from_formula(
formula: str,
data: DataFrame,
data: pandas.DataFrame,
*,
weights: IVDataLike | None = None,
weight_type: str = "robust",
Expand Down Expand Up @@ -1214,7 +1215,7 @@ def fit(
Convergence criteria. Measured as covariance normalized change in
parameters across iterations where the covariance estimator is
based on the first step parameter estimates.
initial_weight : ndarray
initial_weight : numpy.ndarray
Initial weighting matrix to use in the first step. If not
specified, uses the average outer-product of the set containing
the exogenous variables and instruments.
Expand Down Expand Up @@ -1379,7 +1380,7 @@ def __init__(
@staticmethod
def from_formula(
formula: str,
data: DataFrame,
data: pandas.DataFrame,
*,
weights: IVDataLike | None = None,
weight_type: str = "robust",
Expand Down Expand Up @@ -1536,7 +1537,7 @@ def estimate_parameters(
def fit(
self,
*,
starting: Float64Array | Series | None = None,
starting: Float64Array | pandas.Series | None = None,
display: bool = False,
cov_type: str = "robust",
debiased: bool = False,
Expand Down Expand Up @@ -1664,7 +1665,7 @@ def __init__(
def _gmm_model_from_formula(
cls: type[IVGMM] | type[IVGMMCUE],
formula: str,
data: DataFrame,
data: pandas.DataFrame,
weights: IVDataLike | None,
weight_type: str,
**weight_config: Any,
Expand Down
8 changes: 5 additions & 3 deletions linearmodels/iv/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from functools import cached_property
from typing import Any, Union

import numpy
from numpy import (
array,
asarray,
Expand All @@ -25,6 +26,7 @@
squeeze,
)
from numpy.linalg import inv
import pandas
from pandas import DataFrame, Series, concat, to_numeric
import scipy.stats as stats
from statsmodels.iolib.summary import SimpleTable, fmt_2cols, fmt_params
Expand Down Expand Up @@ -407,8 +409,8 @@ def _update_extra_text(self, extra_text: list[str]) -> list[str]:

def wald_test(
self,
restriction: DataFrame | ndarray | None = None,
value: Series | ndarray | None = None,
restriction: pandas.DataFrame | numpy.ndarray | None = None,
value: pandas.Series | numpy.ndarray | None = None,
*,
formula: str | list[str] | dict[str, float] | None = None,
) -> WaldTestStatistic:
Expand Down Expand Up @@ -524,7 +526,7 @@ def predict(
exog: ArrayLike | None = None,
endog: ArrayLike | None = None,
*,
data: DataFrame | None = None,
data: pandas.DataFrame | None = None,
fitted: bool = True,
idiosyncratic: bool = False,
missing: bool = False,
Expand Down
3 changes: 2 additions & 1 deletion linearmodels/panel/covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
from numpy.linalg import inv
import pandas
from pandas import DataFrame, MultiIndex

from linearmodels.iv.covariance import (
Expand Down Expand Up @@ -669,7 +670,7 @@ def __init__(
y: Float64Array,
x: Float64Array,
params: Float64Array,
all_params: DataFrame,
all_params: pandas.DataFrame,
*,
debiased: bool = False,
bandwidth: float | None = None,
Expand Down
Loading

0 comments on commit 09b150f

Please sign in to comment.