Datasets:
Download scripts/ds_prices.py from Lilambd/empire-eval: direct link, hf CLI and curl.
- Browser
- Download file 9.16 kB
-
https://huggingface.co/datasets/Lilambd/empire-eval/resolve/main/scripts/ds_prices.py
- Command line
-
hf download hf://datasets/Lilambd/empire-eval/scripts/ds_prices.py
-
curl -L -o ds_prices.py https://huggingface.co/datasets/Lilambd/empire-eval/resolve/main/scripts/ds_prices.py
9.16 kB
| import pandas as pd | |
| from common import cname, long_features | |
| DS = 'Lilambd/world-prices' | |
| REVISION = 'hf-main@2026-11-03 (monthly to 2026-08)' | |
| LICENSE = 'CC BY 4.0' | |
| SH = 'World Prices Long Record' | |
| STR = {'data/monthly.csv': ['unit', 'period'], 'data/yearly.csv': ['unit']} | |
| KEYS = {'data/monthly.csv': ['unit', 'period', 'feature'], 'data/yearly.csv': ['unit', 'year', 'feature'], 'data/features_country.csv': ['iso3', 'feature'], 'data/feature_doc.csv': ['feature']} | |
| MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | |
| def build(B): | |
| s = B.store | |
| doc = s['data/feature_doc.csv'] | |
| name = {r.feature: r.definition.split(': ', 1)[-1] for r in doc.itertuples()} | |
| m = s['data/monthly.csv'] | |
| w = m[m.unit_kind == 'world'] | |
| wf = sorted(w.feature.unique()) | |
| for _ in range(60): | |
| f = B.rng.choice(wf) | |
| sub = w[w.feature == f] | |
| r = sub.iloc[B.rng.randrange(len(sub))] | |
| what = f'the World Bank Pink Sheet price of {name[f]}' if f.startswith('px_') else f'the World Bank {name[f]} price index (2010=100)' | |
| B.add('lookup', f"In the {SH}, what was {what} in {MONTHS[int(r.month) - 1]} {int(r.year)} (nominal USD, Pink Sheet units)?" if f.startswith('px_') else f"In the {SH}, what was {what} in {MONTHS[int(r.month) - 1]} {int(r.year)}?", | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['period', '==', r.period]], 'col': 'value'}, tol={'rel': 0.005}, skills=['table_lookup', 'temporal']) | |
| for _ in range(30): | |
| f = B.rng.choice([x for x in wf if x.startswith('px_')]) | |
| y = B.rng.randint(1985, 2025) | |
| B.add('rank', f"In the {SH}, in which month of {y} was the Pink Sheet price of {name[f]} highest? Answer as YYYY-MM.", | |
| {'op': 'argmax', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['year', '==', y]], 'col': 'value', 'return': 'period'}, difficulty=2, skills=['ranking', 'temporal']) | |
| for _ in range(25): | |
| f = B.rng.choice([x for x in wf if x.startswith('px_')]) | |
| y = B.rng.randint(1990, 2025) | |
| B.add('aggregate', f"In the {SH}, what was the average of the 12 monthly Pink Sheet prices of {name[f]} in {y}?", | |
| {'op': 'mean', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['year', '==', y]], 'col': 'value'}, tol={'rel': 0.01}, difficulty=2, skills=['aggregation', 'temporal']) | |
| for _ in range(20): | |
| f = B.rng.choice([x for x in wf if x.startswith('px_')]) | |
| y1 = B.rng.randint(1990, 2015) | |
| y2 = B.rng.randint(y1 + 5, 2025) | |
| B.add('temporal', f"In the {SH}, by what factor did the Pink Sheet price of {name[f]} change from January {y1} to January {y2} (Jan {y2} price divided by Jan {y1} price)?", | |
| {'op': 'ratio', 'parts': [ | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['period', '==', f'{y2}-01']], 'col': 'value'}, | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['period', '==', f'{y1}-01']], 'col': 'value'}]}, | |
| tol={'rel': 0.01}, difficulty=2, skills=['arithmetic', 'temporal']) | |
| for _ in range(15): | |
| f = B.rng.choice([x for x in wf if x.startswith('px_')]) | |
| y = B.rng.randint(2000, 2025) | |
| thr_rows = w[(w.feature == f) & (w.year == y)] | |
| if len(thr_rows) < 12: | |
| continue | |
| thr = float(f'{thr_rows.value.median():.3g}') | |
| B.add('count', f"In the {SH}, in how many months of {y} was the Pink Sheet price of {name[f]} above {thr:g}?", | |
| {'op': 'count', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['year', '==', y], ['value', '>', thr]]}, difficulty=2, skills=['filter', 'count', 'temporal']) | |
| for _ in range(12): | |
| a, b = B.sample([x for x in wf if x.startswith('pxi_')], 2) | |
| y = B.rng.randint(2011, 2025) | |
| B.add('compare', f"In the {SH}, in June {y}, which Pink Sheet index was higher: {name[a]} or {name[b]}?", | |
| {'op': 'compare', 'labels': [name[a], name[b]], 'parts': [ | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', a], ['period', '==', f'{y}-06']], 'col': 'value'}, | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', b], ['period', '==', f'{y}-06']], 'col': 'value'}]}, difficulty=2, skills=['comparison']) | |
| for f in B.sample(wf, 12): | |
| per = B.rng.choice(['2026-10', '2026-12', '2027-03']) | |
| y, mo = per.split('-') | |
| B.add('unanswerable', f"In the {SH}, what was the price or index value of {name[f]} in {MONTHS[int(mo) - 1]} {y}? If the dataset has no such month, answer null.", | |
| {'op': 'absent', 'file': 'data/monthly.csv', 'where': [['unit', '==', 'WLD'], ['feature', '==', f], ['period', '==', per]]}, skills=['abstention', 'temporal'], | |
| note='Monthly data runs to 2026-08 in this revision.') | |
| # 31 country CPI series repeat (unit, feature, period) with different values (two base years mixed, | |
| # found by the quality check 2026-11-03). Any question touching such a series could have two answers: skip them. | |
| d = m[m.duplicated(['unit', 'feature', 'period'], keep=False)] | |
| bad = set(zip(d.unit, d.feature)) | |
| c = m[(m.unit_kind == 'country') & ~pd.Series(list(zip(m.unit, m.feature)), index=m.index).isin(bad)] | |
| for _ in range(30): | |
| r = c.iloc[B.rng.randrange(len(c))] | |
| kind = r.feature.replace('cpi_', '') | |
| B.add('lookup', f"In the {SH}, what was the {kind} CPI index level of {cname(r.unit)} in {r.period}?", | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', r.unit], ['feature', '==', r.feature], ['period', '==', r.period]], 'col': 'value'}, tol={'rel': 0.005}, skills=['table_lookup', 'temporal', 'code_resolution']) | |
| for _ in range(15): | |
| r = c[c.feature == 'cpi_headline'].pipe(lambda d: d.iloc[B.rng.randrange(len(d))]) | |
| y = int(r.year) | |
| if y < 2000 or y > 2025: | |
| continue | |
| B.add('temporal', f"In the {SH}, by what factor did the headline CPI index of {cname(r.unit)} change from December {y - 1} to December {y} (Dec {y} level divided by Dec {y - 1} level)?", | |
| {'op': 'ratio', 'parts': [ | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', r.unit], ['feature', '==', 'cpi_headline'], ['period', '==', f'{y}-12']], 'col': 'value'}, | |
| {'op': 'lookup', 'file': 'data/monthly.csv', 'where': [['unit', '==', r.unit], ['feature', '==', 'cpi_headline'], ['period', '==', f'{y - 1}-12']], 'col': 'value'}]}, | |
| difficulty=3, skills=['arithmetic', 'temporal'], tol={'rel': 0.01}) | |
| y = s['data/yearly.csv'] | |
| ys = y[y.unit_kind.isin(['us_state', 'country']) & y.feature.str.startswith('px_')] | |
| for r in ys.loc[B.sample(ys.index, 25)].itertuples(): | |
| who = f'the US state {r.unit}' if r.unit_kind == 'us_state' else cname(r.unit) | |
| B.add('lookup', f"In the {SH}, what was {name.get(r.feature, r.feature)} for {who} in {r.year}?", | |
| {'op': 'lookup', 'file': 'data/yearly.csv', 'where': [['unit', '==', r.unit], ['feature', '==', r.feature], ['year', '==', int(r.year)]], 'col': 'value'}, tol={'rel': 0.005}, skills=['table_lookup']) | |
| us = y[(y.unit_kind == 'us_state') & (y.feature == 'px_us_elec_residential')] | |
| for yr in B.sample(sorted(us.year.unique()), 8): | |
| B.add('rank', f"In the {SH}, which US state had the highest EIA residential electricity price ($/MMBtu) in {yr}? Answer with the state code.", | |
| {'op': 'argmax', 'file': 'data/yearly.csv', 'where': [['unit_kind', '==', 'us_state'], ['feature', '==', 'px_us_elec_residential'], ['year', '==', int(yr)]], 'col': 'value', 'return': 'unit'}, difficulty=2, skills=['ranking']) | |
| eu = y[(y.unit_kind == 'country') & (y.feature == 'px_eu_hh_elec')] | |
| for yr in B.sample(sorted(eu.year.unique()), 6): | |
| B.add('rank', f"In the {SH}, which country had the highest Eurostat household electricity price (EUR/kWh, all taxes) in {yr}? Answer with the ISO3 code.", | |
| {'op': 'argmax', 'file': 'data/yearly.csv', 'where': [['unit_kind', '==', 'country'], ['feature', '==', 'px_eu_hh_elec'], ['year', '==', int(yr)]], 'col': 'value', 'return': 'unit'}, difficulty=2, skills=['ranking']) | |
| for f in B.sample(list(doc.feature), 10): | |
| B.add('documentation', f"In the {SH} feature documentation, what caveat is given for the feature `{f}`?", | |
| {'op': 'lookup', 'file': 'data/feature_doc.csv', 'where': [['feature', '==', f]], 'col': 'caveat'}, skills=['documentation'], note='Free-text answer; score with --lenient or an LLM judge.') | |
| long_features(B, 'data/features_country.csv', n_lookup=30, n_rank=4, n_cmp=8, n_count=4, n_absent=8, ds_short=SH) | |