From 0a3c4bdc00f427964a27343f843cd824ea4deb6f Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Sun, 20 Oct 2024 18:14:32 +0100 Subject: [PATCH] CLN: Fix various small lint issues and docs --- doc/source/conf.py | 2 +- doc/source/types.rst | 34 ++++++++------------------- examples/asset-pricing_formulas.ipynb | 2 +- examples/iv_advanced-examples.ipynb | 1 - examples/iv_basic-examples.ipynb | 5 ++-- examples/iv_using-formulas.ipynb | 1 - examples/system_examples.ipynb | 9 ++++--- examples/system_three-stage-ls.ipynb | 2 +- linearmodels/iv/model.py | 12 +++++----- linearmodels/panel/data.py | 2 -- linearmodels/system/model.py | 4 ++-- linearmodels/typing/__init__.py | 31 ++++++++++-------------- linearmodels/typing/data.py | 23 +++++++----------- 13 files changed, 48 insertions(+), 80 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 8a6dfd51f7..1dcc2a42fb 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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" diff --git a/doc/source/types.rst b/doc/source/types.rst index 4950d618be..a51aab6f15 100644 --- a/doc/source/types.rst +++ b/doc/source/types.rst @@ -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 diff --git a/examples/asset-pricing_formulas.ipynb b/examples/asset-pricing_formulas.ipynb index f24342eb24..1fc0007964 100644 --- a/examples/asset-pricing_formulas.ipynb +++ b/examples/asset-pricing_formulas.ipynb @@ -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", diff --git a/examples/iv_advanced-examples.ipynb b/examples/iv_advanced-examples.ipynb index 2453e07449..adcce1ca2b 100644 --- a/examples/iv_advanced-examples.ipynb +++ b/examples/iv_advanced-examples.ipynb @@ -115,7 +115,6 @@ "metadata": {}, "outputs": [], "source": [ - "from statsmodels.api import OLS, add_constant\n", "\n", "data[\"const\"] = 1\n", "controls = [\"const\"] + controls" diff --git a/examples/iv_basic-examples.ipynb b/examples/iv_basic-examples.ipynb index e355fe8115..e405e03685 100644 --- a/examples/iv_basic-examples.ipynb +++ b/examples/iv_basic-examples.ipynb @@ -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", @@ -802,7 +803,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.12.7" }, "pycharm": { "stem_cell": { diff --git a/examples/iv_using-formulas.ipynb b/examples/iv_using-formulas.ipynb index ba3e805c4b..18c493ca30 100644 --- a/examples/iv_using-formulas.ipynb +++ b/examples/iv_using-formulas.ipynb @@ -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", diff --git a/examples/system_examples.ipynb b/examples/system_examples.ipynb index 959fbcbc02..bde6c22724 100644 --- a/examples/system_examples.ipynb +++ b/examples/system_examples.ipynb @@ -161,7 +161,6 @@ "metadata": {}, "outputs": [], "source": [ - "import pandas as pd\n", "from linearmodels.system import SUR\n", "\n", "mod = SUR(mod_data)\n", @@ -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", @@ -780,7 +779,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.12.7" }, "pycharm": { "stem_cell": { diff --git a/examples/system_three-stage-ls.ipynb b/examples/system_three-stage-ls.ipynb index cf443fec3b..072c5a388d 100644 --- a/examples/system_three-stage-ls.ipynb +++ b/examples/system_three-stage-ls.ipynb @@ -75,7 +75,7 @@ "metadata": {}, "outputs": [], "source": [ - "from linearmodels import IV2SLS, IV3SLS, SUR, IVSystemGMM" + "from linearmodels import IV2SLS, IV3SLS, IVSystemGMM" ] }, { diff --git a/linearmodels/iv/model.py b/linearmodels/iv/model.py index 0691f9f70e..bf937fe7b4 100644 --- a/linearmodels/iv/model.py +++ b/linearmodels/iv/model.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/linearmodels/panel/data.py b/linearmodels/panel/data.py index a16c389048..012f6b967b 100644 --- a/linearmodels/panel/data.py +++ b/linearmodels/panel/data.py @@ -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 ----- diff --git a/linearmodels/system/model.py b/linearmodels/system/model.py index 418b7efeda..f2e94bb104 100644 --- a/linearmodels/system/model.py +++ b/linearmodels/system/model.py @@ -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 @@ -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 diff --git a/linearmodels/typing/__init__.py b/linearmodels/typing/__init__.py index a63caf11ab..58db64889e 100644 --- a/linearmodels/typing/__init__.py +++ b/linearmodels/typing/__init__.py @@ -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 @@ -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 diff --git a/linearmodels/typing/data.py b/linearmodels/typing/data.py index 0edec8caf1..ded9b02cd0 100644 --- a/linearmodels/typing/data.py +++ b/linearmodels/typing/data.py @@ -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 @@ -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",