Skip to content

Commit

Permalink
Implement a few fixes (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens authored Mar 27, 2024
1 parent 44a1403 commit 7b6ec37
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ infer_latex_dependencies = true
filterwarnings = [
"ignore:Using or importing the ABCs from 'collections'",
"ignore:the imp module is deprecated",
"ignore:indexing past lexsort depth may impact performance.",
"ignore:Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead.",
"ignore:In a future version of pandas all arguments of concat except for the argument 'objs' will be keyword-only",
"ignore:Please use `MemoizeJac` from the `scipy.optimize` namespace",
Expand Down
7 changes: 7 additions & 0 deletions src/estimagic/estimation/estimate_msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
transform_free_cov_to_cov,
transform_free_values_to_params_tree,
)
from estimagic.optimization.optimize_result import OptimizeResult
from estimagic.optimization.optimize import minimize
from estimagic.parameters.block_trees import block_tree_to_matrix, matrix_to_block_tree
from estimagic.parameters.conversion import Converter, get_converter
Expand Down Expand Up @@ -328,6 +329,7 @@ def func(x):
_params=estimates,
_weights=weights,
_converter=converter,
_optimize_result=opt_res,
_internal_weights=internal_weights,
_internal_moments_cov=internal_moments_cov,
_internal_jacobian=int_jac,
Expand Down Expand Up @@ -463,6 +465,7 @@ class MomentsResult:
_internal_jacobian: np.ndarray
_empirical_moments: Any
_has_constraints: bool
_optimize_result: Union[OptimizeResult, None] = None
_jacobian: Any = None
_no_jacobian_reason: Union[str, None] = None
_cache: Dict = field(default_factory=dict)
Expand Down Expand Up @@ -504,6 +507,10 @@ def _get_free_cov(self, method, n_samples, bounds_handling, seed):
def params(self):
return self._params

@property
def optimize_result(self):
return self._optimize_result

@property
def weights(self):
return self._weights
Expand Down
36 changes: 35 additions & 1 deletion src/estimagic/visualization/estimation_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def estimation_table(
if return_type == "render_inputs":
out = render_inputs
elif str(return_type).endswith("tex"):
out = render_latex(
out = _render_latex(
**render_inputs,
show_footer=show_footer,
append_notes=append_notes,
Expand Down Expand Up @@ -229,6 +229,7 @@ def estimation_table(
return_type.write_text(out)


@suppress_performance_warnings
def render_latex(
body,
footer,
Expand Down Expand Up @@ -280,6 +281,39 @@ def render_latex(
latex_str (str): The resulting string with Latex tabular code.
"""
return _render_latex(
body=body,
footer=footer,
render_options=render_options,
show_footer=show_footer,
append_notes=append_notes,
notes_label=notes_label,
significance_levels=significance_levels,
custom_notes=custom_notes,
siunitx_warning=siunitx_warning,
show_index_names=show_index_names,
show_col_names=show_col_names,
show_col_groups=show_col_groups,
escape_special_characters=escape_special_characters,
)


def _render_latex(
body,
footer,
render_options=None,
show_footer=True,
append_notes=True,
notes_label="Note:",
significance_levels=(0.1, 0.05, 0.01),
custom_notes=None,
siunitx_warning=True,
show_index_names=False,
show_col_names=True,
show_col_groups=True,
escape_special_characters=True,
):
"""See docstring of render_latex for more information."""
if not pd.__version__ >= "1.4.0":
raise ValueError(
r"""render_latex or estimation_table with return_type="latex" requires
Expand Down
4 changes: 4 additions & 0 deletions tests/estimation/test_estimate_msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pandas as pd
import pytest
from estimagic.optimization.optimize_result import OptimizeResult
from estimagic.estimation.estimate_msm import estimate_msm
from estimagic.shared.check_option_dicts import (
check_numdiff_options,
Expand Down Expand Up @@ -64,6 +65,9 @@ def test_estimate_msm(simulate_moments, moments_cov, optimize_options):
# check that minimization works
aaae(calculated.params, expected_params)

# assert that optimization result exists and is of correct type
assert isinstance(calculated.optimize_result, OptimizeResult)

# check that cov works
calculated_cov = calculated.cov()
if isinstance(calculated_cov, pd.DataFrame):
Expand Down

0 comments on commit 7b6ec37

Please sign in to comment.