benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a269663c-08de-5f8c-8153-b53c5299dddb

Problem

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

complete prompt

import numpy as np
import pandas as pd
from datetime import datetime

# Constants
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'

def task_func(result):
    """
    Calculate the mean, median, min, max, and standard deviation of the "from_user" values in "result" 
    and add the current date and time in the format YYYY-mm-dd HHL:MM:SS to the summary.
    The global constant DATE_FORMAT is used to transform the currnet date and time into this format.


    Parameters:
    result (list of dict): A list of dictionaries containing the key "from_user" whose numeric values are to be analyzed.

    Returns:
    Series: A pandas Series with the statistical summary, including 'mean', 'median', 'min', 'max', 'std', and 'current_time'.
            If the input contains no "from_user" values all statistical values are set to np.nan

    Data Structures:
    - Uses numpy arrays for efficient statistical computations.

    Raises:
    - ValueError: If the "from_user" values are not numeric.

    Requirements:
    - numpy
    - pandas
    - datetime

    Example:
    >>> result = [{"hi": 7, "bye": 4, "from_user": 0}, {"from_user": 0}, {"from_user": 1}]
    >>> stats = task_func(result)
    >>> print(stats['mean'], stats['median'], stats['min'], stats['max'], stats['std'])
    0.3333333333333333 0.0 0 1 0.4714045207910317
    >>> result = [{"test": 7, "hallo": 4, "from_user": 1.3},
    ...           {"from_user": 2},
    ...           {"from_user": 4.6},
    ...           {"from_user": -2.3, "b": 1},
    ...           {"a": "test", "from_user": 12.12},
    ...          ]
    >>> summary = task_func(result)
    """

instruct prompt

Calculate the mean, median, min, max, and standard deviation of the "from_user" values in "result" and add the current date and time in the format YYYY-mm-dd HHL:MM:SS to the summary. The global constant DATE_FORMAT is used to transform the currnet date and time into this format. Data Structures: - Uses numpy arrays for efficient statistical computations.
The function should raise the exception for: ValueError: If the "from_user" values are not numeric.
The function should output with:
    Series: A pandas Series with the statistical summary, including 'mean', 'median', 'min', 'max', 'std', and 'current_time'.
    If the input contains no "from_user" values all statistical values are set to np.nan
You should write self-contained code starting with:

Code

import numpy as np
import pandas as pd
from datetime import datetime
# Constants
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
def task_func(result):

code prompt

Code

import numpy as np
import pandas as pd
from datetime import datetime
# Constants
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
def task_func(result):

entry point

task_func

libs

  • pandas
  • datetime
  • numpy

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