benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 5445ab17-1c50-5594-b4f9-f164e6a8d383
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
import matplotlib.pyplot as plt
# Constants
CATEGORIES = ["A", "B", "C", "D", "E"]
def task_func(data_list):
"""
Processes a list of category labels to create a histogram that visualizes their distribution.
This histogram compares the distribution of a predefined set of categories (A, B, C, D, E)
with any additional categories found in the input list.
Parameters:
- data_list (list): A list containing category labels (strings).
Returns:
- Axes object (matplotlib.axes._axes.Axes): The histogram displaying the distribution of categories.
Requirements:
- pandas
- matplotlib
Notes:
- The function evaluates the distribution of predefined categories ('A', 'B', 'C', 'D', 'E') and checks for uniformity.
If the distribution is not uniform, a warning message of "The distribution of predefined categories is not uniform." is printed.
- Categories in the data_list that are not among the predefined categories are identified and included in the histogram.
- The ax.bar call in the function creates a bar plot on the axes object. It uses the following parameters:
* all_categories: The categories to be displayed on the x-axis, including both predefined and extra categories.
* category_counts.reindex(all_categories, fill_value=0): The counts of each category, where categories not found
in the data_list are assigned a count of 0.
* width=0.8: Sets the width of the bars in the bar plot.
* align="center": Aligns the bars with the center of the x-ticks.
Raises:
- ValueError: If the input data_list is empty, the function raises a ValueError with the message "The data list is empty."
In this case, no histogram is generated and the function terminates.
Example:
>>> data = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
>>> ax = task_func(data)
>>> ax.get_xticks()
array([0., 1., 2., 3., 4., 5., 6.])
"""
instruct prompt
Processes a list of category labels to create a histogram that visualizes their distribution. This histogram compares the distribution of a predefined set of categories (A, B, C, D, E) with any additional categories found in the input list.
Note that: Notes: The function evaluates the distribution of predefined categories ('A', 'B', 'C', 'D', 'E') and checks for uniformity. If the distribution is not uniform, a warning message of "The distribution of predefined categories is not uniform." is printed. Categories in the data_list that are not among the predefined categories are identified and included in the histogram. The ax.bar call in the function creates a bar plot on the axes object. It uses the following parameters: * all_categories: The categories to be displayed on the x-axis, including both predefined and extra categories. * category_counts.reindex(all_categories, fill_value=0): The counts of each category, where categories not found in the data_list are assigned a count of 0. * width=0.8: Sets the width of the bars in the bar plot. * align="center": Aligns the bars with the center of the x-ticks.
The function should raise the exception for: ValueError: If the input data_list is empty, the function raises a ValueError with the message "The data list is empty." In this case, no histogram is generated and the function terminates.
The function should output with:
Axes object (matplotlib.axes._axes.Axes): The histogram displaying the distribution of categories.
You should write self-contained code starting with:
Code
import pandas as pd
import matplotlib.pyplot as plt
# Constants
CATEGORIES = ["A", "B", "C", "D", "E"]
def task_func(data_list):
code prompt
Code
import pandas as pd
import matplotlib.pyplot as plt
# Constants
CATEGORIES = ["A", "B", "C", "D", "E"]
def task_func(data_list):
entry point
task_func
libs
- pandas
- matplotlib
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
initial import