benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 55f9208b-5c52-587a-9abf-1966f2cdb83e

Problem

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

complete prompt

import requests
import pandas as pd


def task_func(api_url):
    """
    Fetches data from a specified API, processes the JSON response, converts it into a pandas DataFrame,
    and plots the data using matplotlib.
    If the data is empty, no plot is generated. If the API request fails, it raises an HTTPError.
    The function also checks if the provided API URL is a string.

    Parameters:
    - api_url (str): The URL of the API to fetch data from.

    Returns:
    - DataFrame: A pandas DataFrame with the parsed data from the API.
    - Axes or None: A matplotlib Axes object representing the plot of the data, or None if the data is empty.

    Raises:
    - HTTPError: If the API request fails due to issues like network problems, invalid response, etc.
    - TypeError: If the `api_url` is not a string.

    Requirements:
    - requests
    - pandas
    - matplotlib.pyplot

    Example:
    >>> df, plot = task_func("https://api.example.com/data")
    >>> df.head()
    >>> if plot:
    >>>     plot.show()
    """

instruct prompt

Fetches data from a specified API, processes the JSON response, converts it into a pandas DataFrame, and plots the data using matplotlib. If the data is empty, no plot is generated. If the API request fails, it raises an HTTPError. The function also checks if the provided API URL is a string.
The function should raise the exception for: HTTPError: If the API request fails due to issues like network problems, invalid response, etc. TypeError: If the `api_url` is not a string.
The function should output with:
    DataFrame: A pandas DataFrame with the parsed data from the API.
    Axes or None: A matplotlib Axes object representing the plot of the data, or None if the data is empty.
You should write self-contained code starting with:

Code

import requests
import pandas as pd
def task_func(api_url):

code prompt

Code

import requests
import pandas as pd
def task_func(api_url):

entry point

task_func

libs

  • pandas
  • requests

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