Skip to content

Commit

Permalink
Merge branch 'main' into dark_mode_logo
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens authored Mar 6, 2024
2 parents a9a2480 + 656319d commit ccc71c4
Show file tree
Hide file tree
Showing 30 changed files with 316 additions and 55 deletions.
1 change: 1 addition & 0 deletions .envs/testenv-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- tranquilo>=0.0.4 # dev, tests
- seaborn # dev, tests
- pip: # dev, tests, docs
- DFO-LS # dev, tests
- Py-BOBYQA # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .envs/testenv-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- tranquilo>=0.0.4 # dev, tests
- seaborn # dev, tests
- pip: # dev, tests, docs
- DFO-LS # dev, tests
- Py-BOBYQA # dev, tests
Expand Down
31 changes: 31 additions & 0 deletions .envs/testenv-pandas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: estimagic
channels:
- conda-forge
- nodefaults
dependencies:
- pandas<2.0.0
- nlopt # dev, tests
- pip # dev, tests, docs
- pytest # dev, tests
- pytest-cov # tests
- pytest-xdist # dev, tests
- statsmodels # dev, tests
- bokeh<=2.4.3 # run, tests
- click # run, tests
- cloudpickle # run, tests
- joblib # run, tests
- numpy>=1.17.0 # run, tests
- plotly # run, tests
- pybaum >= 0.1.2 # run, tests
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- tranquilo>=0.0.4 # dev, tests
- seaborn # dev, tests
- pip: # dev, tests, docs
- DFO-LS # dev, tests
- Py-BOBYQA # dev, tests
- fides==0.7.4 # dev, tests
- kaleido # dev, tests
- simoptlib==1.0.1 # dev, tests
- -e ../
10 changes: 9 additions & 1 deletion .envs/update_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ def main():
test_env_others = deepcopy(test_env)
test_env_others.insert(_insert_idx, " - cyipopt<=1.2.0")

## test environment for pandas version 1
test_env_pandas = deepcopy(test_env)
test_env_pandas = [line for line in test_env_pandas if "pandas" not in line]
test_env_pandas.insert(_insert_idx, " - pandas<2.0.0")

# create docs testing environment

docs_env = [line for line in lines if _keep_line(line, "docs")]
docs_env.append(" - -e ../") # add local installation

# write environments
for name, env in zip(["linux", "others"], [test_env_linux, test_env_others]):
for name, env in zip(
["linux", "others", "pandas"],
[test_env_linux, test_env_others, test_env_pandas],
):
# Specify newline to avoid wrong line endings on Windows.
# See: https://stackoverflow.com/a/69869641
Path(f".envs/testenv-{name}.yml").write_text(
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
steps:
- uses: actions/checkout@v3
- name: create build environment
Expand Down Expand Up @@ -72,6 +73,36 @@ jobs:
run: |
micromamba activate estimagic
pytest -m "not slow and not jax"
run-tests-with-old-pandas:
# This job is only for testing if estimagic works with older pandas versions, as
# many pandas functions we use will be deprecated in pandas 3. estimagic's behavior
# for older verions is handled in src/estimagic/compat.py.
name: Run tests for ${{ matrix.os}} on ${{ matrix.python-version }} with pandas 1
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- '3.11'
steps:
- uses: actions/checkout@v3
- name: create build environment
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: ./.envs/testenv-pandas.yml
environment-name: estimagic
cache-env: true
extra-specs: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate estimagic
pytest tests/visualization
pytest tests/parameters
pytest tests/inference
code-in-docs:
name: Run code snippets in documentation
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ instance/
docs/_build/
docs/build/
docs/source/_build/
docs/source/getting_started/*.db
docs/source/getting_started/*.db-shm
docs/source/getting_started/*.db-wal
docs/source/**/*.db
docs/source/**/*.db-shm
docs/source/**/*.db-wal
docs/source/refs.bib.bak

# PyBuilder
Expand Down
5 changes: 5 additions & 0 deletions docs/source/_static/images/video.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"myst_nb",
"sphinxcontrib.bibtex",
"sphinx_panels",
"sphinx_copybutton",
]

myst_enable_extensions = [
Expand Down
2 changes: 1 addition & 1 deletion docs/source/development/eep-00-governance-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| | `Hans-Martin von Gaudecker <https://github.com/hmgaudecker>`_, |
| | `Annica Gehlen <https://github.com/amageh>`_, |
| | `Sebastian Gsell <https://github.com/segsell>`_, |
| | `Tim Mensinger <https://github.com/timmens>_, |
| | `Tim Mensinger <https://github.com/timmens>`_, |
| | `Mariam Petrosyan <https://github.com/mpetrosian>`_, |
| | `Tobias Raabe <https://github.com/tobiasraabe>`_, |
| | `Klara Röhrl <https://github.com/roecla>`_ |
Expand Down
15 changes: 15 additions & 0 deletions docs/source/getting_started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ reference for more experienced users.
</div>
</a>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="../videos.html" id="index-link">
<div class="card text-center intro-card shadow" style="width: 100%;">
<img src="../_static/images/video.svg" class="card-img-top"
alt="video icon" height="60"
>
<div class="card-body flex-fill">
<h5 class="card-title">Videos</h5>
<p class="card-text">
Collection of tutorials, talks, and screencasts on estimagic.
</p>
</div>
</div>
</a>
</div>
</div>
</div>
```
Expand Down
15 changes: 15 additions & 0 deletions docs/source/how_to_guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ an introduction to its basic functionality, check out our tutorials.
</div>
</a>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="../videos.html" id="index-link">
<div class="card text-center intro-card shadow" style="width: 100%;">
<img src="../_static/images/video.svg" class="card-img-top"
alt="video icon" height="60"
>
<div class="card-body flex-fill">
<h5 class="card-title">Videos</h5>
<p class="card-text">
Collection of tutorials, talks, and screencasts on estimagic.
</p>
</div>
</div>
</a>
</div>
</div>
</div>
```
Expand Down
27 changes: 18 additions & 9 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ For a complete introduction to optimization in estimagic, check out the
</div>
</a>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="videos.html" id="index-link">
<div class="card text-center intro-card shadow" style="width: 100%;">
<img src="_static/images/video.svg" class="card-img-top"
alt="video icon" height="60"
>
<div class="card-body flex-fill">
<h5 class="card-title">Videos</h5>
<p class="card-text">
Collection of tutorials, talks, and screencasts on estimagic.
</p>
</div>
</div>
</a>
</div>
</div>
</div>
```
Expand All @@ -135,6 +150,9 @@ getting_started/index
how_to_guides/index
explanations/index
reference_guides/index
development/index
videos
algorithms
```

## Highlights
Expand Down Expand Up @@ -176,15 +194,6 @@ reference_guides/index
**Useful links for search:** {ref}`genindex` | {ref}`modindex` | {ref}`search`
```{toctree}
---
hidden: true
maxdepth: 1
---
development/index
algorithms
```
[how to do multistart]: how_to_guides/optimization/how_to_do_multistart_optimizations
[how to use logging]: how_to_guides/optimization/how_to_use_logging
[msm tutorial]: getting_started/estimation/first_msm_estimation_with_estimagic
87 changes: 87 additions & 0 deletions docs/source/videos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
(list_of_videos)=

# Videos

Check out our tutorials, talks and screencasts about estimagic.

## Talks and tutorials

### EuroSciPy 2023 (Talk)

```{raw} html
<iframe
src="https://www.youtube.com/embed/5xYn0v1zEsY"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```

### EuroSciPy 2023 (Tutorial)

```{raw} html
<iframe
src="https://www.youtube.com/embed/LQo5NDFKH1Q"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```

### SciPy 2022 (Tutorial)

```{raw} html
<iframe
src="https://www.youtube.com/embed/ftlw0rARrtI"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```

## Screencasts

The screencasts are part of the course _Effective Programming Practices for Economists_,
taught at the University of Bonn by
[Hans-Martin von Gaudecker](https://www.wiwi.uni-bonn.de/gaudecker/), and previously
also [Janoś Gabler](https://github.com/janosg). You can find all screencasts of the
course on the
[course webite](https://effective-programming-practices.vercel.app/landing-page.html).
Here, we show the screencasts about numerical optimization and estimagic.

### Introduction to numerical optimization

```{raw} html
<iframe
src="https://www.youtube.com/embed/hOZueB4Cn1Y"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```

### Using estimagic’s minimize and maximize

```{raw} html
<iframe
src="https://www.youtube.com/embed/QqTGE3nq0q8"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```

### Visualizing optimizer histories

```{raw} html
<iframe
src="https://www.youtube.com/embed/wQWWW8rlxmY"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```

### Choosing optimization algorithms

```{raw} html
<iframe
src="https://www.youtube.com/embed/tJ7Xba3wcxY"
style="width: 100%; aspect-ratio: 16 / 9;"
allowfullscreen>
</iframe>
```
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
- sphinx-panels # docs
- sphinxcontrib-bibtex # docs
- tranquilo>=0.0.4 # dev, tests
- seaborn # dev, tests
- pip: # dev, tests, docs
- DFO-LS # dev, tests
- Py-BOBYQA # dev, tests
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ filterwarnings = [
"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",
"ignore:`scipy.optimize.optimize.MemoizeJac` is deprecated",
"ignore:Some algorithms did not converge. Their walltime has been set to a very high value instead of infinity because Timedeltas do notsupport infinite values",
"ignore:In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences",
"ignore:distutils Version classes are deprecated. Use packaging.version instead",
Expand All @@ -91,6 +92,7 @@ filterwarnings = [
"ignore:Widget.widget_types is deprecated",
"ignore:Widget.widgets is deprecated",
"ignore:Parallelization together with",
"ignore:Conversion of an array with ndim > 0 to a scalar is deprecated",
]
addopts = ["--doctest-modules"]
markers = [
Expand Down
33 changes: 33 additions & 0 deletions src/estimagic/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Compatibility module.
Contains wrapper functions to handle compatibility issues between different versions of
external libraries.
"""

from estimagic.config import IS_PANDAS_VERSION_NEWER_OR_EQUAL_TO_2_1_0


def pd_df_map(df, func, na_action=None, **kwargs):
"""Apply a function to a Dataframe elementwise.
pandas has depricated the .applymap() function with version 2.1.0. This function
calls either .map() (if pandas version is greater or equal to 2.1.0) or .applymap()
(if pandas version is smaller than 2.1.0).
Args:
df (pd.DataFrame): A pandas DataFrame.
func (callable): Python function, returns a single value from a single value.
na_action (str): If 'ignore', propagate NaN values, without passing them to
func. If None, pass NaN values to func. Default is None.
**kwargs: Additional keyword arguments to pass as keywords arguments to func.
Returns:
pd.DataFrame: Transformed DataFrame.
"""
if IS_PANDAS_VERSION_NEWER_OR_EQUAL_TO_2_1_0:
out = df.map(func, na_action=na_action, **kwargs)
else:
out = df.applymap(func, na_action=na_action, **kwargs)
return out
Loading

0 comments on commit ccc71c4

Please sign in to comment.