Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: Fix various small lint issues and docs #624

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
# You can specify multiple suffix as a list of string:
#
# source_suffix = [".rst", ".md"]
source_suffix = ".rst"
source_suffix = {".rst": "restructuredtext"}

# The master toctree document.
master_doc = "index"
Expand Down
34 changes: 10 additions & 24 deletions doc/source/types.rst
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
Type Aliases
============

.. module:: linearmodels.typing.data

.. automodule:: linearmodels.typing.data

.. autoclass::

ArrayLike
Float64Array
Int64Array
Int32Array
IntArray
BoolArray
AnyArray
Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] # pragma: no cover


.. module:: linearmodels.typing

.. automodule:: linearmodels.typing

.. autoclass::

Numeric
OptionalNumeric
.. autoclass:: linearmodels.typing.Numeric
.. autoclass:: linearmodels.typing.OptionalNumeric
.. autoclass:: linearmodels.typing.data.ArrayLike
.. autoclass:: linearmodels.typing.data.Float64Array
.. autoclass:: linearmodels.typing.data.Int64Array
.. autoclass:: linearmodels.typing.data.Int32Array
.. autoclass:: linearmodels.typing.data.IntArray
.. autoclass:: linearmodels.typing.data.BoolArray
.. autoclass:: linearmodels.typing.data.AnyArray
.. autoclass:: linearmodels.typing.data.Uint32Array
2 changes: 1 addition & 1 deletion examples/asset-pricing_formulas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"metadata": {},
"outputs": [],
"source": [
"from linearmodels.asset_pricing import LinearFactorModel, TradedFactorModel\n",
"from linearmodels.asset_pricing import LinearFactorModel\n",
"\n",
"formula = \"NoDur + Chems + S1V1 + S5V5 + S1M1 + S5M5 ~ MktRF + HML + Mom\"\n",
"mod = LinearFactorModel.from_formula(formula, data)\n",
Expand Down
1 change: 0 additions & 1 deletion examples/iv_advanced-examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"metadata": {},
"outputs": [],
"source": [
"from statsmodels.api import OLS, add_constant\n",
"\n",
"data[\"const\"] = 1\n",
"controls = [\"const\"] + controls"
Expand Down
5 changes: 3 additions & 2 deletions examples/iv_basic-examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,10 @@
"metadata": {},
"outputs": [],
"source": [
"v = IV2SLS(data[endog], data[exog + instr], None, None).fit().resids\n",
"import pandas as pd\n",
"\n",
"v = IV2SLS(data[endog], data[exog + instr], None, None).fit().resids\n",
"\n",
"res_direct = IV2SLS(\n",
" data[dep], pd.concat([v, data[exog]], axis=1), data[endog], data[instr]\n",
").fit(cov_type=\"unadjusted\")\n",
Expand Down Expand Up @@ -802,7 +803,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.12.7"
},
"pycharm": {
"stem_cell": {
Expand Down
1 change: 0 additions & 1 deletion examples/iv_using-formulas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from linearmodels.datasets import meps\n",
"from linearmodels.iv import IV2SLS\n",
"\n",
Expand Down
9 changes: 4 additions & 5 deletions examples/system_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from linearmodels.system import SUR\n",
"\n",
"mod = SUR(mod_data)\n",
Expand All @@ -181,14 +180,14 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"\n",
"cov = res.sigma\n",
"std = np.sqrt(np.diag(res.sigma)[:, None])\n",
"regions = [k for k in mod_data.keys()]\n",
"corr = pd.DataFrame(cov / (std @ std.T), columns=regions, index=regions)\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"\n",
"sns.heatmap(corr, vmax=0.8, square=True)\n",
"plt.show()\n",
"\n",
Expand Down Expand Up @@ -780,7 +779,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.12.7"
},
"pycharm": {
"stem_cell": {
Expand Down
2 changes: 1 addition & 1 deletion examples/system_three-stage-ls.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"metadata": {},
"outputs": [],
"source": [
"from linearmodels import IV2SLS, IV3SLS, SUR, IVSystemGMM"
"from linearmodels import IV2SLS, IV3SLS, IVSystemGMM"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions linearmodels/iv/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ class _IVGMMBase(_IVModelBase):
Observation weights used in estimation
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down Expand Up @@ -1066,7 +1066,7 @@ class IVGMM(_IVGMMBase):
Observation weights used in estimation
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down Expand Up @@ -1139,7 +1139,7 @@ def from_formula(
Observation weights used in estimation
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down Expand Up @@ -1342,7 +1342,7 @@ class IVGMMCUE(_IVGMMBase):
Observation weights used in estimation
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down Expand Up @@ -1418,7 +1418,7 @@ def from_formula(
Observation weights used in estimation
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down Expand Up @@ -1706,7 +1706,7 @@ def _gmm_model_from_formula(
Observation weights used in estimation
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down
2 changes: 0 additions & 2 deletions linearmodels/panel/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ class PanelData:
copy : bool
Flag indicating whether to copy the input. Only has an effect when
x is a DataFrame
cast : bool
Flag indicating to case the data to double precision.

Notes
-----
Expand Down
4 changes: 2 additions & 2 deletions linearmodels/system/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ class IVSystemGMM(_SystemModelBase):
if weight_type is "unadjusted"
weight_type : str
Name of moment condition weight function to use in the GMM estimation
**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down Expand Up @@ -2185,7 +2185,7 @@ def from_formula(
* "unadjusted", "homoskedastic" - Assume moments are homoskedastic
* "robust", "heteroskedastic" - Allow for heteroskedasticity

**weight_config
weight_config
Additional keyword arguments to pass to the moment condition weight
function

Expand Down
31 changes: 12 additions & 19 deletions linearmodels/typing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

from collections.abc import Hashable, Sequence
from typing import TYPE_CHECKING, Any, Optional, Union
from typing import Any, Optional, Union

import numpy as np
from pandas import DataFrame, Series
Expand Down Expand Up @@ -32,19 +30,14 @@
AnyPandas = Union[Series, DataFrame]
Label = Optional[Hashable]

if TYPE_CHECKING:
Float64Array = np.ndarray[Any, np.dtype[np.float64]] # pragma: no cover
Int64Array = np.ndarray[Any, np.dtype[np.int64]] # pragma: no cover
Int32Array = np.ndarray[Any, np.dtype[np.int32]] # pragma: no cover
IntArray = np.ndarray[Any, np.dtype[np.int_]] # pragma: no cover
BoolArray = np.ndarray[Any, np.dtype[np.bool_]] # pragma: no cover
AnyArray = np.ndarray[Any, Any] # pragma: no cover
NumericArray = Union[ # pragma: no cover
np.ndarray[Any, np.dtype[np.signedinteger[Any]]], # pragma: no cover
np.ndarray[Any, np.dtype[np.unsignedinteger[Any]]], # pragma: no cover
np.ndarray[Any, np.dtype[np.floating[Any]]], # pragma: no cover
] # pragma: no cover
else:
IntArray = Float64Array = Int64Array = Int32Array = BoolArray = AnyArray = (
NumericArray
) = np.ndarray
Float64Array = np.ndarray[Any, np.dtype[np.float64]] # pragma: no cover
Int64Array = np.ndarray[Any, np.dtype[np.int64]] # pragma: no cover
Int32Array = np.ndarray[Any, np.dtype[np.int32]] # pragma: no cover
IntArray = np.ndarray[Any, np.dtype[np.int_]] # pragma: no cover
BoolArray = np.ndarray[Any, np.dtype[np.bool_]] # pragma: no cover
AnyArray = np.ndarray[Any, Any] # pragma: no cover
NumericArray = Union[ # pragma: no cover
np.ndarray[Any, np.dtype[np.signedinteger[Any]]], # pragma: no cover
np.ndarray[Any, np.dtype[np.unsignedinteger[Any]]], # pragma: no cover
np.ndarray[Any, np.dtype[np.floating[Any]]], # pragma: no cover
] # pragma: no cover
23 changes: 8 additions & 15 deletions linearmodels/typing/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Union
from typing import Any, Union

import numpy as np
import pandas as pd
Expand All @@ -18,18 +16,13 @@

NDArray = Union[np.ndarray]

if TYPE_CHECKING:
Float64Array = np.ndarray[Any, np.dtype[np.float64]] # pragma: no cover
Int64Array = np.ndarray[Any, np.dtype[np.int64]] # pragma: no cover
Int32Array = np.ndarray[Any, np.dtype[np.int32]] # pragma: no cover
IntArray = np.ndarray[Any, np.dtype[np.int_]] # pragma: no cover
BoolArray = np.ndarray[Any, np.dtype[np.bool_]] # pragma: no cover
AnyArray = np.ndarray[Any, Any] # pragma: no cover
Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] # pragma: no cover
else:
Uint32Array = IntArray = Float64Array = Int64Array = Int32Array = BoolArray = (
AnyArray
) = NDArray
Float64Array = np.ndarray[Any, np.dtype[np.float64]] # pragma: no cover
Int64Array = np.ndarray[Any, np.dtype[np.int64]] # pragma: no cover
Int32Array = np.ndarray[Any, np.dtype[np.int32]] # pragma: no cover
IntArray = np.ndarray[Any, np.dtype[np.int_]] # pragma: no cover
BoolArray = np.ndarray[Any, np.dtype[np.bool_]] # pragma: no cover
AnyArray = np.ndarray[Any, Any] # pragma: no cover
Uint32Array = np.ndarray[Any, np.dtype[np.uint32]] # pragma: no cover

__all__ = [
"Float64Array",
Expand Down
Loading