benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f7c21bae-500e-5b59-a4ee-5a9853c45a78

Problem

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

complete prompt

import sqlite3
import pandas as pd
import os


def task_func(db_file, table_name, column_name, pattern='\d+[xX]'):
    """
    Find all matches with a regex pattern in a list of strings in an SQL database.
    
    The function loads an sql database and selects all entries from the specified
    table. Matches are returned in a DataFrame.

    Parameters:
    db_file (str): The SQLite database file.
    table_name (str): The name of the table to search.
    column_name (str): The name of the column to search.
    pattern (str, optional): The regex pattern to search for. Defaults to '\d+[xX]'.

    Returns:
    DataFrame: A pandas DataFrame with the matches.
        
    Raises:
    ValueError: If db_file does not exist.

    Requirements:
    - sqlite3
    - pandas
    - os
        
    Example:
    >>> result = task_func('task_func_data/sample.db', 'test_table', 'test_column')
    >>> print(result.head(10))
        id              test_column
    0    1                  4x4 car
    1    2           New 3x3 puzzle
    3    4  Product with 5X feature
    55  56                   1xsafe
    56  57                 3xmother
    57  58                  5xenjoy
    58  59                   2xhome
    59  60                 3xanswer
    60  61                   5xgirl
    61  62                   5xkind
    """

instruct prompt

Find all matches with a regex pattern in a list of strings in an SQL database. The function loads an sql database and selects all entries from the specified table. Matches are returned in a DataFrame.
The function should raise the exception for: ValueError: If db_file does not exist.
The function should output with:
    DataFrame: A pandas DataFrame with the matches.
You should write self-contained code starting with:

Code

import sqlite3
import pandas as pd
import os
def task_func(db_file, table_name, column_name, pattern='\d+[xX]'):

code prompt

Code

import sqlite3
import pandas as pd
import os
def task_func(db_file, table_name, column_name, pattern='\d+[xX]'):

entry point

task_func

libs

  • sqlite3
  • pandas
  • os

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