Skip to content

Commit

Permalink
Fix directory structure in the best practices guide on parametrizatio…
Browse files Browse the repository at this point in the history
…ns. (#208)
  • Loading branch information
tobiasraabe authored Jan 26, 2022
1 parent 42da034 commit db2eb85
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
3 changes: 2 additions & 1 deletion docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
`Anaconda.org <https://anaconda.org/conda-forge/pytask>`_.


0.1.6 - 2022-xx-xx
0.1.6 - 2022-01-27
------------------

- :gh:`191` adds a guide on how to profile pytask to the developer's guide.
Expand All @@ -23,6 +23,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
- :gh:`201` adds tests for ``_pytask.mark_utils``.
- :gh:`204` removes internal traceback frames from exceptions raised somewhere in
pytask.
- :gh:`208` fixes the best practices guide for parametrizations.


0.1.5 - 2022-01-10
Expand Down
65 changes: 39 additions & 26 deletions docs/source/how_to_guides/bp_parametrizations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,50 @@ First, let us take a look at the folder and file structure of such a project.

.. code-block::
src
│ config.py
my_project
├───pytask.ini or tox.ini or setup.cfg
├───data
│ data_0.csv
│ data_1.csv
│ data_2.csv
│ data_3.csv
├───src
│ └───my_project
│ ├────config.py
│ │
│ ├───data
│ │ ├────data_0.csv
│ │ ├────data_1.csv
│ │ ├────data_2.csv
│ │ └────data_3.csv
│ │
│ ├───data_preparation
│ │ ├────data_preparation_config.py
│ │ └────task_prepare_data.py
│ │
│ └───estimation
│ ├────estimation_config.py
│ └────task_estimate_models.py
├───data_preparation
│ data_preparation_config.py
│ task_prepare_data.py
└───estimation
estimation_config.py
task_estimate_models.py
├───setup.py
├───.pytask.sqlite3
└───bld
The folder structure, the general ``config.py`` which holds ``SRC`` and ``BLD`` and the
tasks follow the same structure which is advocated for throughout the tutorials.

What is new are the local configuration files in each of the subfolders of ``src`` which
contain objects which are shared across tasks. For example,
What is new are the local configuration files in each of the subfolders of
``my_project`` which contain objects which are shared across tasks. For example,
``data_preparation_config.py`` holds the paths to the processed data and the names of
the data sets.

.. code-block:: python
# Content of data_preparation_config.py
from src.config import BLD
from src.config import SRC
from my_project.config import BLD
from my_project.config import SRC
DATA = ["data_0", "data_1", "data_2", "data_3"]
Expand All @@ -87,9 +100,9 @@ parametrization.
import pytask
from src.data_preparation.data_preparation_config import DATA
from src.data_preparation.data_preparation_config import path_to_input_data
from src.data_preparation.data_preparation_config import path_to_processed_data
from my_project.data_preparation.data_preparation_config import DATA
from my_project.data_preparation.data_preparation_config import path_to_input_data
from my_project.data_preparation.data_preparation_config import path_to_processed_data
def _create_parametrization(data):
Expand Down Expand Up @@ -121,7 +134,7 @@ an explicit id.
.. code-block::
# With id
.../src/data_preparation/task_prepare_data.py::task_prepare_data[data_0]
.../my_project/data_preparation/task_prepare_data.py::task_prepare_data[data_0]
Next, we move to the estimation to see how we can build another parametrization upon the
previous one.
Expand All @@ -130,8 +143,8 @@ previous one.
# Content of estimation_config.py
from src.config import BLD
from src.data_preparation.data_preparation_config import DATA
from my_project.config import BLD
from my_project.data_preparation.data_preparation_config import DATA
_MODELS = ["linear_probability", "logistic_model", "decision_tree"]
Expand Down Expand Up @@ -164,9 +177,9 @@ And, here is the task file.
import pytask
from src.data_preparation.data_preparation_config import path_to_processed_data
from src.data_preparation.estimation_config import ESTIMATIONS
from src.data_preparation.estimation_config import path_to_estimation_result
from my_project.data_preparation.data_preparation_config import path_to_processed_data
from my_project.data_preparation.estimation_config import ESTIMATIONS
from my_project.data_preparation.estimation_config import path_to_estimation_result
def _create_parametrization(estimations):
Expand Down

0 comments on commit db2eb85

Please sign in to comment.