Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
7
25
category
stringclasses
4 values
instruction
stringlengths
30
154
setup
stringlengths
32
144
expected
unknown
solution
stringlengths
18
232
oc_col_to_list
output_convention
Return the 'a' column as a plain Python list.
df = pl.DataFrame({'a': [1, 2, 3]})
[ 1, 2, 3 ]
result = df['a'].to_list()
oc_scalar_sum
output_convention
Return the sum of the 'v' column as a plain integer.
df = pl.DataFrame({'v': [1, 2, 3]})
6
result = int(df['v'].sum())
oc_first_value
output_convention
Return the value in the first row of column 'x' as a plain integer.
df = pl.DataFrame({'x': [42, 7, 9]})
42
result = int(df['x'][0])
oc_row_count
output_convention
Return the number of rows as a plain integer.
df = pl.DataFrame({'a': [1, 2, 3, 4]})
4
result = df.height
oc_column_names
output_convention
Return the list of column names.
df = pl.DataFrame({'name': ['a'], 'age': [1]})
[ "name", "age" ]
result = df.columns
oc_kv_dict
output_convention
Return a dict mapping each value of 'k' to its value of 'v'.
df = pl.DataFrame({'k': ['a', 'b'], 'v': [1, 2]})
{ "a": 1, "b": 2 }
result = dict(zip(df['k'].to_list(), df['v'].to_list()))
oc_rows_as_dicts
output_convention
Return every row as a list of dicts.
df = pl.DataFrame({'a': [1, 2], 'b': ['x', 'y']})
[ { "a": 1, "b": "x" }, { "a": 2, "b": "y" } ]
result = df.to_dicts()
oc_max_float
output_convention
Return the maximum value of 'v' as a plain float.
df = pl.DataFrame({'v': [1.5, 9.25, 3.0]})
9.25
result = float(df['v'].max())
oc_mean_rounded
output_convention
Return the mean of 'v' rounded to 2 decimal places, as a plain float.
df = pl.DataFrame({'v': [1.0, 2.0, 4.0]})
2.33
result = round(float(df['v'].mean()), 2)
oc_any_bool
output_convention
Return True if any value in 'v' is greater than 10, otherwise False, as a plain bool.
df = pl.DataFrame({'v': [3, 15, 7]})
true
result = bool((df['v'] > 10).any())
oc_first_row_dict
output_convention
Return the first row as a dict.
df = pl.DataFrame({'a': [1, 2], 'b': ['x', 'y']})
{ "a": 1, "b": "x" }
result = df.head(1).to_dicts()[0]
oc_distinct_count
output_convention
Return the number of distinct values in 'c' as a plain integer.
df = pl.DataFrame({'c': ['a', 'b', 'a']})
2
result = int(df['c'].n_unique())
pt_sort_desc
pandas_trap
Sort rows by 'score' from highest to lowest and return the 'name' column as a list.
df = pl.DataFrame({'name': ['x', 'y', 'z'], 'score': [7, 12, 9]})
[ "y", "z", "x" ]
result = df.sort('score', descending=True)['name'].to_list()
pt_groupby_sum
pandas_trap
Group by 'team', sum 'pts', and return a dict mapping team to its total.
df = pl.DataFrame({'team': ['a', 'b', 'a'], 'pts': [3, 5, 2]})
{ "a": 5, "b": 5 }
g = df.group_by('team').agg(pl.col('pts').sum()) result = dict(zip(g['team'].to_list(), g['pts'].to_list()))
pt_fill_nulls
pandas_trap
Replace null values in 'v' with 0 and return 'v' as a list.
df = pl.DataFrame({'v': [1, None, 3]})
[ 1, 0, 3 ]
result = df.with_columns(pl.col('v').fill_null(0))['v'].to_list()
pt_cast_type
pandas_trap
Convert column 'a' to 64-bit integers and return it as a list.
df = pl.DataFrame({'a': ['1', '2', '3']})
[ 1, 2, 3 ]
result = df.with_columns(pl.col('a').cast(pl.Int64))['a'].to_list()
pt_merge_join
pandas_trap
Inner join df and df2 on 'id', sort by 'id' ascending, and return the 'city' column as a list.
df = pl.DataFrame({'id': [1, 2, 3], 'n': ['a', 'b', 'c']}) df2 = pl.DataFrame({'id': [2, 3, 4], 'city': ['x', 'y', 'z']})
[ "x", "y" ]
result = df.join(df2, on='id', how='inner').sort('id')['city'].to_list()
pt_drop_duplicates
pandas_trap
Remove duplicate rows and return the remaining rows as a list of dicts, ordered by 'a' ascending.
df = pl.DataFrame({'a': [1, 1, 2], 'b': ['x', 'x', 'y']})
[ { "a": 1, "b": "x" }, { "a": 2, "b": "y" } ]
result = df.unique().sort('a').to_dicts()
pt_isin_filter
pandas_trap
Keep only rows where 'c' is either 'b' or 'd', and return 'c' as a list.
df = pl.DataFrame({'c': ['a', 'b', 'c', 'd']})
[ "b", "d" ]
result = df.filter(pl.col('c').is_in(['b', 'd']))['c'].to_list()
pt_value_counts
pandas_trap
Count how many times each value appears in 'c' and return a dict mapping value to count.
df = pl.DataFrame({'c': ['a', 'b', 'a', 'a']})
{ "a": 3, "b": 1 }
g = df.group_by('c').agg(pl.len().alias('n')) result = dict(zip(g['c'].to_list(), g['n'].to_list()))
pt_rename_column
pandas_trap
Rename column 'old' to 'new' and return the list of column names.
df = pl.DataFrame({'old': [1, 2]})
[ "new" ]
result = df.rename({'old': 'new'}).columns
pt_string_upper
pandas_trap
Convert every value in 's' to uppercase and return 's' as a list.
df = pl.DataFrame({'s': ['ab', 'cd']})
[ "AB", "CD" ]
result = df.with_columns(pl.col('s').str.to_uppercase())['s'].to_list()
pt_filter_select_cols
pandas_trap
Keep only rows where 'a' is greater than 1, and return only columns 'a' and 'c' as a list of dicts.
df = pl.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})
[ { "a": 2, "c": 8 }, { "a": 3, "c": 9 } ]
result = df.filter(pl.col('a') > 1).select(['a', 'c']).to_dicts()
pt_nunique_per_group
pandas_trap
For each group in 'g', count the distinct values of 'v'. Return a dict mapping group to that count.
df = pl.DataFrame({'g': ['x', 'x', 'y'], 'v': [1, 1, 2]})
{ "x": 1, "y": 1 }
g = df.group_by('g').agg(pl.col('v').n_unique().alias('n')) result = dict(zip(g['g'].to_list(), g['n'].to_list()))
sa_with_columns
stale_api
Add a column 'b' equal to 'a' multiplied by 2, and return 'b' as a list.
df = pl.DataFrame({'a': [1, 2]})
[ 2, 4 ]
result = df.with_columns((pl.col('a') * 2).alias('b'))['b'].to_list()
sa_row_count_expr
stale_api
Count the number of rows per group in 'g'. Return a dict mapping group to count.
df = pl.DataFrame({'g': ['a', 'a', 'b']})
{ "a": 2, "b": 1 }
g = df.group_by('g').agg(pl.len().alias('n')) result = dict(zip(g['g'].to_list(), g['n'].to_list()))
sa_cum_sum
stale_api
Return the running cumulative sum of 'v' as a list.
df = pl.DataFrame({'v': [1, 2, 3]})
[ 1, 3, 6 ]
result = df.with_columns(pl.col('v').cum_sum().alias('c'))['c'].to_list()
sa_gather
stale_api
Return the values of 'v' at row positions 0 and 2, as a list.
df = pl.DataFrame({'v': [10, 20, 30, 40]})
[ 10, 30 ]
result = df['v'].gather([0, 2]).to_list()
sa_str_length
stale_api
Return the character length of each value in 's' as a list.
df = pl.DataFrame({'s': ['ab', 'abcd']})
[ 2, 4 ]
result = df.with_columns(pl.col('s').str.len_chars().alias('n'))['n'].to_list()
sa_rank_descending
stale_api
Rank the values in 'v' from highest to lowest, where 1 is the highest. Return the ranks as a list in original row order.
df = pl.DataFrame({'v': [5, 9, 2]})
[ 2, 1, 3 ]
result = df.with_columns(pl.col('v').rank(method='min', descending=True).cast(pl.Int64).alias('r'))['r'].to_list()
sa_map_elements
stale_api
Apply a Python function to each value of 'n' that returns the value squared, and return the results as a list.
df = pl.DataFrame({'n': [1, 2, 3]})
[ 1, 4, 9 ]
result = df.with_columns(pl.col('n').map_elements(lambda x: x * x, return_dtype=pl.Int64).alias('sq'))['sq'].to_list()
sa_list_namespace
stale_api
Column 'xs' holds lists. Return the length of each list as a list of integers.
df = pl.DataFrame({'xs': [[1, 2], [3, 4, 5]]})
[ 2, 3 ]
result = df.with_columns(pl.col('xs').list.len().alias('n'))['n'].to_list()
sa_explode
stale_api
Expand column 'xs' so each list element becomes its own row, then return 'xs' as a list.
df = pl.DataFrame({'g': ['a', 'b'], 'xs': [[1, 2], [3]]})
[ 1, 2, 3 ]
result = df.explode('xs')['xs'].to_list()
sa_top_k
stale_api
Return the 2 largest values in 'v', sorted from highest to lowest, as a list.
df = pl.DataFrame({'v': [5, 1, 9, 3]})
[ 9, 5 ]
result = df['v'].top_k(2).sort(descending=True).to_list()
sa_shift_fill
stale_api
Shift the 'v' column down by one position, filling the first slot with 0. Return as a list.
df = pl.DataFrame({'v': [1, 2, 3]})
[ 0, 1, 2 ]
result = df.with_columns(pl.col('v').shift(1, fill_value=0).alias('s'))['s'].to_list()
sa_pivot
stale_api
Pivot the table so rows come from 'r', columns from 'c', and cell values from 'v'. Return the result as a list of dicts sorted by 'r'.
df = pl.DataFrame({'r': ['x', 'x', 'y'], 'c': ['a', 'b', 'a'], 'v': [1, 2, 3]})
[ { "r": "x", "a": 1, "b": 2 }, { "r": "y", "a": 3, "b": null } ]
result = df.pivot(on='c', index='r', values='v').sort('r').to_dicts()
h_rank_over_group
hard
Within each 'grp', rank rows by 'val' descending where 1 is the highest. Return the ranks as a list in original row order.
df = pl.DataFrame({'grp': ['a', 'a', 'b', 'b'], 'val': [5, 9, 2, 7]})
[ 2, 1, 2, 1 ]
result = df.with_columns(pl.col('val').rank(method='min', descending=True).over('grp').cast(pl.Int64).alias('r'))['r'].to_list()
h_multi_key_join
hard
Inner join df and df2 on both 'a' and 'b'. Sort by 'a' ascending and return the 'w' column as a list.
df = pl.DataFrame({'a': [1, 1, 2], 'b': ['x', 'y', 'x'], 'v': [10, 20, 30]}) df2 = pl.DataFrame({'a': [1, 2], 'b': ['x', 'x'], 'w': [100, 200]})
[ 100, 200 ]
result = df.join(df2, on=['a', 'b'], how='inner').sort('a')['w'].to_list()
h_conditional_sum
hard
For each group in 'g', sum only the 'v' values where 'ok' is True. Return a dict mapping group to that sum.
df = pl.DataFrame({'g': ['a', 'a', 'b'], 'v': [1, 5, 7], 'ok': [True, False, True]})
{ "a": 1, "b": 7 }
g = df.group_by('g').agg(pl.col('v').filter(pl.col('ok')).sum().alias('s')) result = dict(zip(g['g'].to_list(), g['s'].to_list()))
h_top_n_per_group
hard
For each group in 'g', keep the 2 rows with the largest 'v'. Return the kept 'v' values as a list sorted ascending.
df = pl.DataFrame({'g': ['a', 'a', 'a', 'b', 'b'], 'v': [3, 9, 5, 1, 8]})
[ 1, 5, 8, 9 ]
r = df.filter(pl.col('v').rank(method='ordinal', descending=True).over('g') <= 2) result = sorted(r['v'].to_list())
h_rolling_mean
hard
Compute the rolling mean of 'v' over a window of 2 rows. Return it as a list; the first entry should be null.
df = pl.DataFrame({'v': [1.0, 2.0, 3.0, 4.0]})
[ null, 1.5, 2.5, 3.5 ]
result = df.with_columns(pl.col('v').rolling_mean(window_size=2).alias('m'))['m'].to_list()
h_cumsum_by_group
hard
Compute a cumulative sum of 'v' within each group in 'g'. Return as a list in original row order.
df = pl.DataFrame({'g': ['a', 'a', 'b', 'b'], 'v': [1, 2, 10, 20]})
[ 1, 3, 10, 30 ]
result = df.with_columns(pl.col('v').cum_sum().over('g').alias('c'))['c'].to_list()
h_lag_diff
hard
For each row compute the difference between 'v' and the previous row's 'v'. The first row should be null. Return as a list.
df = pl.DataFrame({'v': [10, 13, 18]})
[ null, 3, 5 ]
result = df.with_columns((pl.col('v') - pl.col('v').shift(1)).alias('d'))['d'].to_list()
h_multi_agg
hard
Group by 'k'. For each group compute the mean of 'v' and the number of rows. Return a dict mapping k to a two-element list [mean, count].
df = pl.DataFrame({'k': ['a', 'a', 'b'], 'v': [1.0, 3.0, 10.0]})
{ "a": [ 2, 2 ], "b": [ 10, 1 ] }
g = df.group_by('k').agg([pl.col('v').mean().alias('m'), pl.len().alias('n')]) result = {k: [m, n] for k, m, n in zip(g['k'].to_list(), g['m'].to_list(), g['n'].to_list())}
h_split_count
hard
Each value in 'tags' is a comma-separated string. Return the total number of tags across all rows as a plain integer.
df = pl.DataFrame({'tags': ['a,b', 'c', 'd,e,f']})
6
result = int(df.with_columns(pl.col('tags').str.split(',').list.len().alias('n'))['n'].sum())
h_when_then_chain
hard
Label each value in 'n' as 'low' if under 10, 'mid' if under 100, otherwise 'high'. Return the labels as a list.
df = pl.DataFrame({'n': [5, 9, 12, 98, 103]})
[ "low", "low", "mid", "mid", "high" ]
result = df.with_columns(pl.when(pl.col('n') < 10).then(pl.lit('low')).when(pl.col('n') < 100).then(pl.lit('mid')).otherwise(pl.lit('high')).alias('l'))['l'].to_list()
h_filter_by_group_size
hard
Keep only the rows whose group in 'g' contains more than one row, then return the 'g' values of those rows as a list sorted ascending.
df = pl.DataFrame({'g': ['a', 'a', 'b', 'c'], 'v': [1, 2, 5, 9]})
[ "a", "a" ]
result = sorted(df.filter(pl.len().over('g') > 1)['g'].to_list())
h_anti_join
hard
Return the 'id' values in df that do NOT appear in df2, sorted ascending, as a list.
df = pl.DataFrame({'id': [1, 2, 3]}) df2 = pl.DataFrame({'id': [2]})
[ 1, 3 ]
result = df.join(df2, on='id', how='anti').sort('id')['id'].to_list()
oc2_sum_float
output_convention
Return the sum of 'v' as a plain float.
df = pl.DataFrame({'v': [1.5, 2.25, 3.0]})
6.75
result = float(df['v'].sum())
oc2_n_columns
output_convention
Return the number of columns as a plain integer.
df = pl.DataFrame({'a': [1], 'b': [2], 'c': [3]})
3
result = len(df.columns)
oc2_shape_list
output_convention
Return the table's shape as a two-element list [rows, columns].
df = pl.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
[ 3, 2 ]
result = [df.height, df.width]
oc2_null_count
output_convention
Return how many nulls are in column 'v', as a plain integer.
df = pl.DataFrame({'v': [1, None, 3, None]})
2
result = int(df['v'].null_count())
oc2_last_row_dict
output_convention
Return the last row as a dict.
df = pl.DataFrame({'a': [1, 2, 3], 'b': ['x', 'y', 'z']})
{ "a": 3, "b": "z" }
result = df.tail(1).to_dicts()[0]
oc2_nth_value
output_convention
Return the value in row index 2 of column 'v' as a plain integer.
df = pl.DataFrame({'v': [10, 20, 30, 40]})
30
result = int(df['v'][2])
oc2_median_float
output_convention
Return the median of 'v' as a plain float.
df = pl.DataFrame({'v': [1.0, 5.0, 3.0]})
3
result = float(df['v'].median())
oc2_all_bool
output_convention
Return True if every value in 'v' is greater than 0, otherwise False, as a plain bool.
df = pl.DataFrame({'v': [3, 8, 1]})
true
result = bool((df['v'] > 0).all())
oc2_all_bool_false
output_convention
Return True if every value in 'v' is greater than 5, otherwise False, as a plain bool.
df = pl.DataFrame({'v': [3, 8, 1]})
false
result = bool((df['v'] > 5).all())
oc2_pairs
output_convention
Return a list of two-element lists pairing each 'k' with its 'v', in row order.
df = pl.DataFrame({'k': ['a', 'b'], 'v': [1, 2]})
[ [ "a", 1 ], [ "b", 2 ] ]
result = [[k, v] for k, v in zip(df['k'].to_list(), df['v'].to_list())]
oc2_dtypes_str
output_convention
Return the data type names of the columns as a list of strings, in column order.
df = pl.DataFrame({'a': [1], 'b': ['x']})
[ "Int64", "String" ]
result = [str(d) for d in df.dtypes]
oc2_unique_sorted_list
output_convention
Return the distinct values of 'c' sorted ascending, as a list.
df = pl.DataFrame({'c': [3, 1, 3, 2]})
[ 1, 2, 3 ]
result = sorted(df['c'].unique().to_list())
oc2_min_int
output_convention
Return the smallest value in 'v' as a plain integer.
df = pl.DataFrame({'v': [7, 2, 9]})
2
result = int(df['v'].min())
oc2_std_rounded
output_convention
Return the standard deviation of 'v' rounded to 3 decimal places, as a plain float.
df = pl.DataFrame({'v': [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]})
2.138
result = round(float(df['v'].std()), 3)
oc2_is_empty
output_convention
Return True if the table has no rows, otherwise False, as a plain bool.
df = pl.DataFrame({'a': [1, 2]})
false
result = df.height == 0
oc2_column_as_strings
output_convention
Return the values of 'n' converted to strings, as a list.
df = pl.DataFrame({'n': [1, 2, 3]})
[ "1", "2", "3" ]
result = [str(x) for x in df['n'].to_list()]
oc2_sum_two_cols
output_convention
Return the combined total of every value in columns 'a' and 'b', as a plain integer.
df = pl.DataFrame({'a': [1, 2], 'b': [10, 20]})
33
result = int(df['a'].sum() + df['b'].sum())
oc2_count_matching
output_convention
Return how many rows have 'v' greater than 5, as a plain integer.
df = pl.DataFrame({'v': [3, 8, 6, 1]})
2
result = int((df['v'] > 5).sum())
pt2_between
pandas_trap
Keep only rows where 'v' is between 10 and 30 inclusive, and return 'v' as a list.
df = pl.DataFrame({'v': [5, 10, 22, 30, 41]})
[ 10, 22, 30 ]
result = df.filter(pl.col('v').is_between(10, 30))['v'].to_list()
pt2_startswith
pandas_trap
Keep only rows where 'sku' starts with 'A', and return 'sku' as a list.
df = pl.DataFrame({'sku': ['A1', 'B2', 'A3']})
[ "A1", "A3" ]
result = df.filter(pl.col('sku').str.starts_with('A'))['sku'].to_list()
pt2_str_replace
pandas_trap
Replace every '-' with '_' in column 's' and return 's' as a list.
df = pl.DataFrame({'s': ['a-b', 'c-d']})
[ "a_b", "c_d" ]
result = df.with_columns(pl.col('s').str.replace_all('-', '_'))['s'].to_list()
pt2_dropna
pandas_trap
Remove rows where 'v' is null and return 'v' as a list.
df = pl.DataFrame({'v': [1, None, 3]})
[ 1, 3 ]
result = df.drop_nulls('v')['v'].to_list()
pt2_abs
pandas_trap
Return the absolute value of every entry in 'v', as a list.
df = pl.DataFrame({'v': [-3, 4, -5]})
[ 3, 4, 5 ]
result = df.with_columns(pl.col('v').abs().alias('o'))['o'].to_list()
pt2_round_col
pandas_trap
Round every value in 'v' to 1 decimal place and return 'v' as a list.
df = pl.DataFrame({'v': [1.24, 3.68]})
[ 1.2, 3.7 ]
result = df.with_columns(pl.col('v').round(1))['v'].to_list()
pt2_clip
pandas_trap
Limit every value in 'v' to a maximum of 10, leaving smaller values unchanged. Return 'v' as a list.
df = pl.DataFrame({'v': [4, 15, 9, 22]})
[ 4, 10, 9, 10 ]
result = df.with_columns(pl.col('v').clip(upper_bound=10))['v'].to_list()
pt2_sort_two_cols
pandas_trap
Sort by 'g' ascending then 'v' descending, and return 'v' as a list.
df = pl.DataFrame({'g': ['b', 'a', 'a'], 'v': [1, 5, 9]})
[ 9, 5, 1 ]
result = df.sort(['g', 'v'], descending=[False, True])['v'].to_list()
pt2_concat_rows
pandas_trap
Stack df on top of df2 into one table and return column 'a' as a list.
df = pl.DataFrame({'a': [1, 2]}) df2 = pl.DataFrame({'a': [3]})
[ 1, 2, 3 ]
result = pl.concat([df, df2])['a'].to_list()
pt2_groupby_two_keys
pandas_trap
Group by both 'g' and 'h', sum 'v', and return the summed values sorted ascending as a list.
df = pl.DataFrame({'g': ['a', 'a', 'b'], 'h': ['x', 'y', 'x'], 'v': [1, 2, 7]})
[ 1, 2, 7 ]
g = df.group_by(['g', 'h']).agg(pl.col('v').sum()) result = sorted(g['v'].to_list())
pt2_idxmax
pandas_trap
Return the row index of the largest value in 'v', as a plain integer.
df = pl.DataFrame({'v': [4, 19, 7]})
1
result = int(df['v'].arg_max())
pt2_head_tail
pandas_trap
Return the last 2 values of 'v' as a list, in row order.
df = pl.DataFrame({'v': [1, 2, 3, 4]})
[ 3, 4 ]
result = df.tail(2)['v'].to_list()
pt2_mean_per_column
pandas_trap
Return a dict mapping each column name to the mean of that column.
df = pl.DataFrame({'a': [2.0, 4.0], 'b': [10.0, 20.0]})
{ "a": 3, "b": 15 }
result = {c: float(df[c].mean()) for c in df.columns}
pt2_nlargest
pandas_trap
Return the 2 largest values of 'v', sorted from highest to lowest, as a list.
df = pl.DataFrame({'v': [5, 22, 13, 8]})
[ 22, 13 ]
result = df.sort('v', descending=True).head(2)['v'].to_list()
pt2_where_mask
pandas_trap
Replace every value in 'v' below 0 with 0, leaving others unchanged. Return 'v' as a list.
df = pl.DataFrame({'v': [-4, 3, -1, 8]})
[ 0, 3, 0, 8 ]
result = df.with_columns(pl.when(pl.col('v') < 0).then(0).otherwise(pl.col('v')).alias('v'))['v'].to_list()
pt2_duplicated
pandas_trap
Return the values of 'v' that appear more than once, sorted ascending, as a list.
df = pl.DataFrame({'v': [1, 2, 2, 3, 3, 3]})
[ 2, 3 ]
g = df.group_by('v').agg(pl.len().alias('n')).filter(pl.col('n') > 1) result = sorted(g['v'].to_list())
pt2_select_dtypes
pandas_trap
Return the names of the columns that hold text values, as a list.
df = pl.DataFrame({'a': [1], 'b': ['x'], 'c': ['y']})
[ "b", "c" ]
result = [c for c, d in zip(df.columns, df.dtypes) if d == pl.String]
pt2_astype_float
pandas_trap
Convert 'a' to floating point numbers and return it as a list.
df = pl.DataFrame({'a': [1, 2]})
[ 1, 2 ]
result = df.with_columns(pl.col('a').cast(pl.Float64))['a'].to_list()
sa2_with_row_index
stale_api
Add a column called 'idx' holding each row's position starting at 0, and return 'idx' as a list.
df = pl.DataFrame({'v': [9, 8, 7]})
[ 0, 1, 2 ]
result = df.with_row_index('idx')['idx'].cast(pl.Int64).to_list()
sa2_cum_max
stale_api
Return the running maximum of 'v' as a list.
df = pl.DataFrame({'v': [3, 1, 7, 5]})
[ 3, 3, 7, 7 ]
result = df.with_columns(pl.col('v').cum_max().alias('o'))['o'].to_list()
sa2_cum_prod
stale_api
Return the running product of 'v' as a list.
df = pl.DataFrame({'v': [2, 3, 2]})
[ 2, 6, 12 ]
result = df.with_columns(pl.col('v').cum_prod().alias('o'))['o'].to_list()
sa2_arg_sort
stale_api
Return the row positions that would sort 'v' in ascending order, as a list.
df = pl.DataFrame({'v': [30, 10, 20]})
[ 1, 2, 0 ]
result = df['v'].arg_sort().cast(pl.Int64).to_list()
sa2_strip_chars
stale_api
Remove leading and trailing whitespace from every value in 's' and return 's' as a list.
df = pl.DataFrame({'s': [' a ', ' b']})
[ "a", "b" ]
result = df.with_columns(pl.col('s').str.strip_chars())['s'].to_list()
sa2_bottom_k
stale_api
Return the 2 smallest values of 'v', sorted ascending, as a list.
df = pl.DataFrame({'v': [8, 2, 5, 9]})
[ 2, 5 ]
result = df['v'].bottom_k(2).sort().to_list()
sa2_concat_str
stale_api
Join columns 'a' and 'b' into one string per row separated by '-', and return the results as a list.
df = pl.DataFrame({'a': ['x', 'y'], 'b': ['1', '2']})
[ "x-1", "y-2" ]
result = df.with_columns(pl.concat_str([pl.col('a'), pl.col('b')], separator='-').alias('o'))['o'].to_list()
sa2_is_duplicated
stale_api
Return a list of booleans saying, for each row, whether its 'v' value occurs more than once.
df = pl.DataFrame({'v': [1, 2, 1]})
[ true, false, true ]
result = df['v'].is_duplicated().to_list()
sa2_unique_maintain_order
stale_api
Return the distinct values of 'c' in the order they first appear, as a list.
df = pl.DataFrame({'c': ['b', 'a', 'b', 'c']})
[ "b", "a", "c" ]
result = df['c'].unique(maintain_order=True).to_list()
sa2_str_to_lower
stale_api
Convert every value in 's' to lowercase and return 's' as a list.
df = pl.DataFrame({'s': ['AB', 'Cd']})
[ "ab", "cd" ]
result = df.with_columns(pl.col('s').str.to_lowercase())['s'].to_list()
sa2_list_sum
stale_api
Column 'xs' holds lists of numbers. Return the sum of each list, as a list of integers.
df = pl.DataFrame({'xs': [[1, 2], [3, 4, 5]]})
[ 3, 12 ]
result = df.with_columns(pl.col('xs').list.sum().alias('o'))['o'].to_list()
sa2_list_first
stale_api
Column 'xs' holds lists. Return the first element of each list, as a list.
df = pl.DataFrame({'xs': [[7, 2], [4, 9, 1]]})
[ 7, 4 ]
result = df.with_columns(pl.col('xs').list.first().alias('o'))['o'].to_list()
sa2_str_contains_literal
stale_api
Keep only rows where 'p' contains the literal text '.csv', and return 'p' as a list.
df = pl.DataFrame({'p': ['a.csv', 'b.txt', 'cxcsv']})
[ "a.csv" ]
result = df.filter(pl.col('p').str.contains('.csv', literal=True))['p'].to_list()
sa2_replace_values
stale_api
Replace the value 2 with 99 in column 'v', leaving other values unchanged. Return 'v' as a list.
df = pl.DataFrame({'v': [1, 2, 3, 2]})
[ 1, 99, 3, 99 ]
result = df.with_columns(pl.col('v').replace(2, 99))['v'].to_list()
sa2_diff
stale_api
Return the difference between each value of 'v' and the previous one. The first entry should be null.
df = pl.DataFrame({'v': [10, 14, 9]})
[ null, 4, -5 ]
result = df.with_columns(pl.col('v').diff().alias('o'))['o'].to_list()
sa2_n_unique_expr
stale_api
Return the number of distinct values in 'c' as a plain integer, computed with a polars expression.
df = pl.DataFrame({'c': ['a', 'b', 'a', 'c']})
3
result = int(df.select(pl.col('c').n_unique()).item())
End of preview. Expand in Data Studio

YAML Metadata Warning:The task_categories "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other

text2polars-bench

An execution-based benchmark for polars code generation, built to measure small language models. 268 tasks across three sets that answer three different questions.

Small models are not merely weak at polars — they are confidently wrong. They reach for pandas (sort_values, fillna, groupby, tolist), methods that are real, familiar, and absent from the library being asked about. This benchmark was built to measure that, and then to measure whether fine-tuning actually fixes it.

The three sets

Set Tasks Question it answers
dev 120 How good is the model at polars?
general 60 Did training it damage ordinary Python ability?
held_out 88 Does any improvement generalise past what was trained?

general and held_out are the point. A single polars score is easy to improve and easy to misread. On our own runs, a model went from 20% to 60% on dev while general collapsed from 83% to 10%, and held_out did not move at all.

Task format

{
  "id": "pt_sort_desc",
  "category": "pandas_trap",
  "instruction": "Sort rows by 'score' from highest to lowest and return the 'name' column as a list.",
  "setup": "df = pl.DataFrame({'name': ['x','y','z'], 'score': [7, 12, 9]})",
  "expected": ["y", "z", "x"],
  "solution": "result = df.sort('score', descending=True)['name'].to_list()"
}

The model is given setup and instruction, and must write code assigning result. Score by executing it and comparing to expected — not by comparing code as text, so a correct answer written differently still counts.

solution is a reference implementation, used to validate the task. It is not shown to the model being evaluated.

Categories in dev

Category Tasks What it isolates
output_convention 30 Returning plain Python rather than a DataFrame
pandas_trap 30 Where the natural pandas idiom differs from polars
stale_api 30 polars renamed it; models know the old name
hard 30 Windows, multi-key joins, nested aggregation

Report per category. A single average hides everything: in our runs stale_api went 0% → 58% while hard did not move at all, and the overall number showed neither.

How held_out was built

This is the set worth explaining, because it is what a self-authored benchmark usually lacks.

  1. Downloaded 752 MIT-licensed polars source files (the pola-rs/polars repository — user guide, docs, test suite).
  2. Counted which operations real code actually uses: 313 distinct, across 32,701 usages.
  3. Kept the operations that were common in real code, never emitted by our training-data generators, and never tested by dev.
  4. Fixed that list before looking at any model score. Choosing it afterwards would mean selecting the questions models happen to fail.
  5. Wrote 100 tasks, then dropped 12 after checking that their non-scaffold operations all appeared in training anyway.

The result measures generalisation to operations a model was not shown.

Validation

Every task has been executed. expected was written independently of solution — one derived from the other would make agreement meaningless rather than evidential. Two authoring errors were caught this way.

Answers are polars-version-specific. Validated against polars 1.43.2.

Limitations

  • Small. 120 / 60 / 88 tasks resolves large effects, not small ones. At n=88 a 4.5-point difference sits at p ≈ 0.6. Report significance, not just percentages.
  • Frontier models saturate dev. Claude Opus 5 scored 100% on an earlier 48-task version. This is a diagnostic for small models, not a frontier benchmark.
  • Synthetic data. Tasks use small illustrative DataFrames, not real analytical workloads.
  • One library, one language. Nothing here supports claims about code generation generally.
  • held_out is held out with respect to a specific training run. If you train on these operations it stops measuring anything. Build a new one.

Provenance and licence

Tasks were authored for this benchmark and are released under MIT.

No third-party code is reproduced. pola-rs/polars (MIT) was used only for frequency analysis — counting which operations appear, to select what held_out should test. operation_frequency.json contains those counts.

Harness

Scoring code, contamination screening, and paired significance testing: https://github.com/royalsanga24/text2polars

Includes per-task records for 16 evaluation runs, so published numbers can be checked without retraining anything.

Downloads last month
12

Models trained or fine-tuned on royalsanga/text2polars-bench