benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 8fcb952c-2dbc-5ab5-a73b-cc60f03abe27

Problem

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

complete prompt

import json
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd


def task_func(json_data: str, key_path: list):
    """
    Extracts and visualizes numerical data from a JSON structure based on a specified path of keys.

    Parameters:
    json_data (str): JSON formatted string.
    key_path (list): List of strings representing the nested keys to locate the data within the JSON.

    Returns:
    matplotlib.figure.Figure: A matplotlib figure showing a boxplot of the data values.

    Raises:
    KeyError: If a specified key is not found.
    ValueError: If no numeric data is found, or the data string is empty or corrupted.

    Requirements:
    - json
    - numpy
    - matplotlib
    - seaborn
    - pandas

    Examples:
    >>> json_data = '{"level1":{"level2":{"data":"1,2,3,4"}}}'
    >>> key_path = ['level1', 'level2', 'data']
    >>> fig = task_func(json_data, key_path)
    >>> isinstance(fig, plt.Figure)
    True
    """

instruct prompt

Extracts and visualizes numerical data from a JSON structure based on a specified path of keys.
The function should raise the exception for: KeyError: If a specified key is not found. ValueError: If no numeric data is found, or the data string is empty or corrupted.
The function should output with:
    matplotlib.figure.Figure: A matplotlib figure showing a boxplot of the data values.
You should write self-contained code starting with:

Code

import json
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
def task_func(json_data: str, key_path: list):

code prompt

Code

import json
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
def task_func(json_data: str, key_path: list):

entry point

task_func

libs

  • pandas
  • matplotlib
  • numpy
  • seaborn
  • json

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