### Install and Run Documentation Tools Source: https://github.com/nixtla/datasetsforecast/blob/main/CONTRIBUTING.md Steps to install 'mintlify' and 'lazydocs', generate documentation files, and serve the documentation locally. ```bash npm i -g mint uv pip install -e '.[dev]' lazydocs lazydocs .datasetsforecast --no-watermark python docs/to_mdx.py cd docs/mintlify mintlify dev ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/nixtla/datasetsforecast/blob/main/CONTRIBUTING.md Commands to install and run pre-commit hooks for maintaining code quality. ```bash pre-commit install pre-commit run --all-files ``` -------------------------------- ### Install datasetsforecast Source: https://github.com/nixtla/datasetsforecast/blob/main/README.md Installs the datasetsforecast library using pip. This is the primary method for adding the library to your Python environment. ```sh pip install datasetsforecast ``` -------------------------------- ### Create Development Environment with uv Source: https://github.com/nixtla/datasetsforecast/blob/main/CONTRIBUTING.md Steps to create a Python virtual environment using 'uv' and install the project in editable mode with development dependencies. ```bash pip install uv uv venv --python 3.10 source .venv/bin/activate # Install the library in editable mode for development uv pip install -e ".[dev]" -U ``` -------------------------------- ### Create Development Environment with conda Source: https://github.com/nixtla/datasetsforecast/blob/main/CONTRIBUTING.md Instructions to set up the development environment using 'conda' and the provided 'environment.yml' file. ```bash conda env create -f environment.yml ``` -------------------------------- ### Clone Repository Source: https://github.com/nixtla/datasetsforecast/blob/main/CONTRIBUTING.md Methods for cloning the datasetsforecast repository using HTTPS, SSH, or GitHub CLI. ```bash git clone https://github.com/Nixtla/datasetsforecast.git ``` ```bash git clone git@github.com:Nixtla/datasetsforecast.git ``` ```bash gh repo clone Nixtla/datasetsforecast ``` -------------------------------- ### Running Tests Source: https://github.com/nixtla/datasetsforecast/blob/main/CONTRIBUTING.md Command to execute tests using pytest within the development environment. ```bash uv run pytest ``` -------------------------------- ### Load PHM2008 Dataset Source: https://github.com/nixtla/datasetsforecast/blob/main/README.md Demonstrates how to load the PHM2008 dataset using the datasetsforecast library. It shows importing the dataset class and using the `load` method to fetch training and testing data, specifying a directory for storage and a group for the data subset. The output displays the shapes of the resulting training and testing dataframes. ```python from datasetsforecast.phm2008 import PHM2008 train_df, test_df = PHM2008.load(directory='data', group='FD001') train_df.shape, test_df.shape ``` -------------------------------- ### Processing Notebook with Initialized Processor Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Executes the processing logic defined in the initialized NBProcessor instance. ```python processor.process() ``` -------------------------------- ### Applying Specific Directives with NBProcessor Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Demonstrates using NBProcessor to apply a specific function (`extract_dir`) with custom directives ('hide', 'polars') to a notebook. ```python NBProcessor(nb_path, procs=partial(extract_dir, dirs='hide,polars')).process() ``` -------------------------------- ### Mapping Processor Functions Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb A dictionary mapping string names to their corresponding notebook processing functions. This allows for dynamic selection of processors. ```python #|export mapper = { 'print_execs': print_execs, 'print_hide': print_hide, 'other_tests': other_tests, 'get_markdown': get_markdown, 'extract_dir': extract_dir, 'no_dir_and_dir': no_dir_and_dir, 'get_all_tests':get_all_tests } ``` -------------------------------- ### Initializing NBProcessor with Specific Directives Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Initializes an NBProcessor instance configured to extract cells containing the 'distributed' directive. ```python processor = NBProcessor(nb_path, partial(extract_dir, dirs='distributed')) ``` -------------------------------- ### Notebook Reading Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Reads a specified notebook file into a notebook object. This is a foundational step for processing notebook content using nbdev. ```python from execnb.nbio import read_nb nb_path = "../nbs/favorita.ipynb" nb = read_nb(nb_path) ``` -------------------------------- ### Applying All Test Cells with NBProcessor Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Applies the `get_all_tests` function to a notebook using NBProcessor, filtering for cells relevant to testing. ```python NBProcessor(nb_path, procs=get_all_tests).process() ``` -------------------------------- ### CLI Function for Notebook Processing Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb A command-line function to process notebooks based on specified directives and processor functions. It utilizes nbdev's NBProcessor for applying custom logic to notebook cells. ```python #|export from functools import partial from fastcore.script import call_parse from nbdev.config import get_config from nbdev.processors import NBProcessor @call_parse def print_dir_in_nb(nb_path:str, dir:str=None, dir_name:str=None, ): if dir_name not in mapper.keys(): raise ValueError(f'Choose processor from the the following: {mapper.keys()}') if dir_name == 'extract_dir': processor = NBProcessor(nb_path, partial(extract_dir, dir=dir)) processor.process() return elif dir_name == 'no_dir_and_dir': processor = NBProcessor(nb_path, partial(no_dir_and_dir, dir=dir)) processor.process() return processor = NBProcessor(nb_path, mapper[dir_name]) processor.process() ``` -------------------------------- ### Extracting Cells by Specific Directives Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints the source code of cells that contain any of the specified directives. Allows for targeted extraction based on notebook metadata. ```python #|export def extract_dir(cell, dirs): for directive in dirs.split(','): if directive in cell.directives_: print(cell.source) ``` -------------------------------- ### Notebook Export Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Exports a notebook to a Python module. This function is part of the nbdev library, used for managing and exporting notebook content. ```python #|export nb_export('cli.ipynb', lib_path='.', name='cli') ``` -------------------------------- ### Extracting Markdown Cells Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints the source code of cells that are of the 'markdown' type. Used for isolating and displaying markdown content. ```python #|export def get_markdown(cell): if cell.cell_type == "markdown": print(cell.source) ``` -------------------------------- ### Extracting All Test-Related Cells Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints code cells that are either untagged or tagged with test-related directives (e.g., 'hide', 'datasets', 'distributed'). Skips cells containing specific skip keywords. ```python #|export tst_flags = 'datasets distributed matplotlib polars pyarrow scipy'.split() to_skip = [ 'showdoc', 'load_ext', 'from nbdev' ] def get_all_tests(cell): if cell.cell_type == "code": if len(cell.directives_) == 0: print(cell.source) elif any(x in tst_flags + ['hide'] for x in cell.directives_): if not (x in cell.source for x in to_skip): print(cell.source) ``` -------------------------------- ### Notebook Cell Access Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Accesses the cells within a loaded notebook object. This allows for iterating through and processing individual cells. ```python nb.cells ``` -------------------------------- ### Extracting Code Cells Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints the source code of cells that are of the 'code' type. Used for isolating and displaying executable code. ```python #|export def get_code(cell): if cell.cell_type == "code": print(cell.source) ``` -------------------------------- ### Conditional Cell Printing (Exec) Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints the source code of a notebook cell if it contains the 'exec' directive. Useful for identifying executable code blocks. ```python #|export def print_execs(cell): if 'exec' in cell.source: print(cell.source) ``` -------------------------------- ### Printing Cells Without Directives Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints the source code of a notebook cell if it has no directives. Useful for identifying standard code cells. ```python #|export def other_tests(cell): if len(cell.directives_) == 0: print(cell.source) ``` -------------------------------- ### Conditional Cell Printing (Hide Directive) Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints the source code of a notebook cell if it has the 'hide' directive. Helps in selectively displaying or hiding code. ```python #|export def print_hide(cell): if 'hide' in cell.directives_: print(cell.source) ``` -------------------------------- ### Printing Cells with or without a Specific Directive Source: https://github.com/nixtla/datasetsforecast/blob/main/scripts/cli.ipynb Prints cells that either have no directives or contain a specific directive. Useful for conditional processing based on directive presence. ```python #|export def no_dir_and_dir(cell, dir): if len(cell.directives_) == 0: print(cell.source) if dir in cell.directives_: print(cell.source) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.