Skip to content

Commit 31e7033

Browse files
authored
Merge pull request #594 from bashtage/numpy-3
COMPAT: Add monkey patch for formulaic
2 parents 02633ad + 0382db7 commit 31e7033

File tree

24 files changed

+79
-40
lines changed

24 files changed

+79
-40
lines changed

ci/azure_template_posix.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ jobs:
152152
testRunTitle: 'Python $(python.version)'
153153
condition: succeededOrFailed()
154154

155-
- task: PublishCodeCoverageResults@1
155+
- task: PublishCodeCoverageResults@2
156156
inputs:
157-
codeCoverageTool: Cobertura
158157
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
159158
condition: and(eq(variables['coverage'], 'true'), ne(variables['test.install'], 'true'))
160159

doc/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import glob
1111
import hashlib
1212
import os
13-
from typing import Dict, List
1413

1514
from packaging.version import parse
1615

examples/system_formulas.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
"from collections import OrderedDict\n",
4747
"\n",
4848
"formula = OrderedDict()\n",
49-
"formula[\n",
50-
" \"benefits\"\n",
51-
"] = \"hrbens ~ educ + exper + expersq + union + south + nrtheast + nrthcen + male\"\n",
49+
"formula[\"benefits\"] = (\n",
50+
" \"hrbens ~ educ + exper + expersq + union + south + nrtheast + nrthcen + male\"\n",
51+
")\n",
5252
"formula[\"earnings\"] = \"hrearn ~ educ + exper + expersq + nrtheast + married + male\""
5353
]
5454
},

linearmodels/asset_pricing/covariance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Covariance estimators for linear factor models
33
"""
4+
45
from __future__ import annotations
56

67
from numpy import empty, ndarray

linearmodels/asset_pricing/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Linear factor models for applications in asset pricing
33
"""
4+
45
from __future__ import annotations
56

67
from typing import Any, Callable, cast

linearmodels/asset_pricing/results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Results for linear factor models
33
"""
4+
45
from __future__ import annotations
56

67
from linearmodels.compat.statsmodels import Summary

linearmodels/compat/formulaic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def monkey_patch_materializers():
2+
from formulaic.materializers.base import FormulaMaterializer
3+
from formulaic.materializers.pandas import PandasMaterializer
4+
5+
if "pandas.DataFrame" not in FormulaMaterializer.REGISTERED_INPUTS:
6+
FormulaMaterializer.REGISTERED_INPUTS["pandas.DataFrame"] = (
7+
FormulaMaterializer.REGISTERED_INPUTS["pandas.core.frame.DataFrame"]
8+
)
9+
if "pandas.DataFrame" not in PandasMaterializer.REGISTERED_INPUTS:
10+
PandasMaterializer.REGISTERED_INPUTS["pandas.DataFrame"] = (
11+
PandasMaterializer.REGISTERED_INPUTS["pandas.core.frame.DataFrame"]
12+
)

linearmodels/iv/_utility.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
from linearmodels.typing import Float64Array
1414

15+
from ..compat.formulaic import monkey_patch_materializers
16+
17+
# Monkey patch parsers if needed, remove once formulaic updated
18+
monkey_patch_materializers()
19+
1520
PARSING_ERROR = """
1621
Conversion of formula blocks to DataFrames failed.
1722
The formula blocks used for conversion were:

linearmodels/iv/absorbing.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def lsmr_annihilate(
125125
return empty_like(y)
126126
use_cache = use_cache and x_hash is not None
127127
regressor_hash = x_hash if x_hash is not None else ""
128-
default_opts: dict[
129-
str, bool | float | str | ArrayLike | None | dict[str, Any]
130-
] = dict(atol=1e-8, btol=1e-8, show=False)
128+
default_opts: dict[str, bool | float | str | ArrayLike | None | dict[str, Any]] = (
129+
dict(atol=1e-8, btol=1e-8, show=False)
130+
)
131131
assert lsmr_options is not None
132132
default_opts.update(lsmr_options)
133133
resids = []
@@ -835,8 +835,9 @@ def _prepare_interactions(self) -> None:
835835
def _first_time_fit(
836836
self,
837837
use_cache: bool,
838-
absorb_options: None
839-
| (dict[str, bool | float | str | ArrayLike | None | dict[str, Any]]),
838+
absorb_options: None | (
839+
dict[str, bool | float | str | ArrayLike | None | dict[str, Any]]
840+
),
840841
method: str,
841842
) -> None:
842843
weights = (
@@ -947,8 +948,9 @@ def fit(
947948
cov_type: str = "robust",
948949
debiased: bool = False,
949950
method: str = "auto",
950-
absorb_options: None
951-
| (dict[str, bool | float | str | ArrayLike | None | dict[str, Any]]) = None,
951+
absorb_options: None | (
952+
dict[str, bool | float | str | ArrayLike | None | dict[str, Any]]
953+
) = None,
952954
use_cache: bool = True,
953955
lsmr_options: dict[str, float | bool] | None = None,
954956
**cov_config: Any,

linearmodels/iv/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Instrumental variable estimators
33
"""
4+
45
from __future__ import annotations
56

67
from typing import Any, TypeVar, Union, cast

0 commit comments

Comments
 (0)