benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e592ef42-7ee6-5ea5-9be6-b8be3771f847

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def task_func(start_date: str, periods: int, freq: str, random_seed: int = 0) -> (pd.DataFrame, plt.Axes):
    """
    Generates and plots a sales forecast starting from a given date, for a specified number of periods and frequency.

    Requirements:
    - pandas
    - numpy
    - matplotlib.pyplot
    
    Parameters:
    - start_date (str): Start date for the forecast in 'YYYY-MM-DD' format.
    - periods (int): Number of periods to forecast.
    - freq (str): Frequency of the forecast (e.g., 'WOM-2FRI' for the second Friday of each month, 'M' for monthly).
    - random_seed (int, optional): Seed for the random number generator to ensure reproducibility.

    Returns:
    - A tuple containing:
        1. A DataFrame with columns ['Date', 'Sales'], where 'Date' is the forecast date and 'Sales' are the forecasted sales.
        2. A matplotlib Axes object for the sales forecast plot.

    Examples:
    >>> df, ax = task_func('2021-01-01', 5, 'WOM-2FRI')
    >>> print(df)
                Sales
    Date             
    2021-01-08    272
    2021-02-12    147
    2021-03-12    217
    2021-04-09    292
    2021-05-14    423
    >>> df, ax = task_func('2022-02-01', 3, 'M', random_seed=42)
    >>> print(df)
                Sales
    Date             
    2022-02-28    202
    2022-03-31    448
    2022-04-30    370
    """

instruct prompt

Generates and plots a sales forecast starting from a given date, for a specified number of periods and frequency.
The function should output with:
    A tuple containing:
    1. A DataFrame with columns ['Date', 'Sales'], where 'Date' is the forecast date and 'Sales' are the forecasted sales.
    2. A matplotlib Axes object for the sales forecast plot.
You should write self-contained code starting with:

Code

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def task_func(start_date: str, periods: int, freq: str, random_seed: int = 0) -> (pd.DataFrame, plt.Axes):

code prompt

Code

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def task_func(start_date: str, periods: int, freq: str, random_seed: int = 0) -> (pd.DataFrame, plt.Axes):

entry point

task_func

libs

  • pandas
  • numpy
  • matplotlib

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import