Skip to content

Commit a6e4ed2

Browse files
committed
Package update
feat: Improve error handling and user experience This update enhances the Python package to better match the Stata package's behavior and improve user experience: Key Changes: - Improved error handling with user-friendly messages - Removed traceback output for invalid inputs - Added consistent header display for all error messages - Matched error message format with Stata package - Updated .gitignore for cleaner repository structure Error Handling Improvements: - Invalid variables now show clean error messages with usage instructions - Invalid country codes display available options - Version errors include current and available versions - Raw data errors provide clear usage guidelines - Download errors show user-friendly messages Repository Structure: - Kept essential package files - Removed unnecessary build artifacts and cache - Preserved package metadata - Maintained test suite and documentation Testing: - All 16 test cases passing - Verified error handling behavior - Tested all user interaction scenarios
1 parent 13b35d7 commit a6e4ed2

File tree

12 files changed

+959
-190
lines changed

12 files changed

+959
-190
lines changed

.gitignore

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ __pycache__/
44
*$py.class
55

66
# Distribution / packaging
7-
*.egg-info/
87
dist/
98
build/
109
*.egg
1110

12-
# Virtual environments
13-
venv/
14-
env/
15-
.env
16-
.venv
17-
ENV/
11+
# Test cache
12+
.pytest_cache/
13+
.coverage
14+
htmlcov/
1815

1916
# IDE related
2017
.idea/
@@ -23,4 +20,8 @@ ENV/
2320
*.swo
2421

2522
# OS related
26-
.DS_Store
23+
.DS_Store
24+
Thumbs.db
25+
26+
# Keep egg-info for package metadata
27+
!global_macro_data.egg-info/

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ pip install global_macro_data
3232
```python
3333
from global_macro_data import gmd
3434

35-
# Get preview data (Singapore 2000-2020)
36-
df = gmd()
37-
3835
# Get data from latest available version
39-
df = gmd(show_preview=False)
36+
df = gmd()
4037

4138
# Get data from a specific version
4239
df = gmd(version="2025_01")
@@ -50,15 +47,30 @@ df = gmd(country=["USA", "CHN", "DEU"])
5047
# Get specific variables
5148
df = gmd(variables=["rGDP", "infl", "unemp"])
5249

50+
# Get raw data for a single variable
51+
df = gmd(variables="rGDP", raw=True)
52+
53+
# List available variables and their descriptions
54+
gmd(vars=True)
55+
56+
# List available countries and their ISO codes
57+
gmd(iso=True)
58+
5359
# Combine parameters
54-
df = gmd(version="2025_01", country=["USA", "CHN"], variables=["rGDP", "unemp", "CPI"])
60+
df = gmd(
61+
version="2025_01",
62+
country=["USA", "CHN"],
63+
variables=["rGDP", "unemp", "CPI"]
64+
)
5565
```
5666

5767
## Parameters
58-
- **version (str)**: Dataset version in format 'YYYY_MM' (e.g., '2025_01'). If None, the latest dataset is used.
59-
- **country (str or list)**: ISO3 country code(s) (e.g., "SGP" or ["MRT", "SGP"]). If None, returns all countries.
60-
- **variables (list)**: List of variable codes to include (e.g., ["rGDP", "unemp"]). If None, all variables are included.
61-
- **show_preview (bool)**: If True and no other parameters are provided, shows a preview.
68+
- **variables (str or list)**: Variable code(s) to include (e.g., "rGDP" or ["rGDP", "unemp"])
69+
- **country (str or list)**: ISO3 country code(s) (e.g., "SGP" or ["MRT", "SGP"])
70+
- **version (str)**: Dataset version in format 'YYYY_MM' (e.g., '2025_01'). If None or "current", uses the latest version
71+
- **raw (bool)**: If True, download raw data for a single variable
72+
- **iso (bool)**: If True, display list of available countries
73+
- **vars (bool)**: If True, display list of available variables
6274

6375
## Release schedule
6476
| Release Date | Details |
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Metadata-Version: 2.4
2+
Name: global-macro-data
3+
Version: 0.3.1
4+
Summary: Global Macro Database by Karsten Müller, Chenzi Xu, Mohamed Lehbib and Ziliang Chen (2025)
5+
Home-page: https://github.com/KMueller-Lab/Global-Macro-Database-Python
6+
Author: Yangbo Wang
7+
Author-email: wangyangbo@ruc.edu.cn
8+
Classifier: Programming Language :: Python :: 3
9+
Classifier: License :: OSI Approved :: MIT License
10+
Classifier: Operating System :: OS Independent
11+
Requires-Python: >=3.6
12+
Description-Content-Type: text/markdown
13+
Requires-Dist: requests
14+
Requires-Dist: pandas
15+
Dynamic: author
16+
Dynamic: author-email
17+
Dynamic: classifier
18+
Dynamic: description
19+
Dynamic: description-content-type
20+
Dynamic: home-page
21+
Dynamic: requires-dist
22+
Dynamic: requires-python
23+
Dynamic: summary
24+
25+
# The Global Macro Database (Python Package)
26+
<a href="https://www.globalmacrodata.com" target="_blank" rel="noopener noreferrer">
27+
<img src="https://img.shields.io/badge/Website-Visit-blue?style=flat&logo=google-chrome" alt="Website Badge">
28+
</a>
29+
30+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
31+
32+
[Link to paper 📄](https://www.globalmacrodata.com/research-paper.html)
33+
34+
This repository complements paper, **Müller, Xu, Lehbib, and Chen (2025)**, which introduces a panel dataset of **46 macroeconomic variables across 243 countries** from historical records beginning in the year **1086** until **2024**, including projections through the year **2030**.
35+
36+
## Features
37+
38+
- **Unparalleled Coverage**: Combines data from **32 contemporary sources** (e.g., IMF, World Bank, OECD) with **78 historical datasets**.
39+
- **Extensive Variables**: GDP, inflation, government finance, trade, employment, interest rates, and more.
40+
- **Harmonized Data**: Resolves inconsistencies and splices all available data together.
41+
- **Scheduled Updates**: Regular releases ensure data reliability.
42+
- **Full Transparency**: All code is open source and available in this repository.
43+
- **Accessible Formats**: Provided in `.dta`, `.csv` and as **<a href="https://github.com/KMueller-Lab/Global-Macro-Database" target="_blank" rel="noopener noreferrer">Stata</a>
44+
/<a href="https://github.com/KMueller-Lab/Global-Macro-Database-Python" target="_blank" rel="noopener noreferrer">Python</a>/<a href="https://github.com/KMueller-Lab/Global-Macro-Database-R" target="_blank" rel="noopener noreferrer">R</a> package**.
45+
46+
## Data access
47+
48+
<a href="https://www.globalmacrodata.com/data.html" target="_blank" rel="noopener noreferrer">Download via website</a>
49+
50+
**Python package:**
51+
```
52+
pip install global_macro_data
53+
```
54+
55+
**How to use (examples)**
56+
```python
57+
from global_macro_data import gmd
58+
59+
# Get data from latest available version
60+
df = gmd()
61+
62+
# Get data from a specific version
63+
df = gmd(version="2025_01")
64+
65+
# Get data for a specific country
66+
df = gmd(country="USA")
67+
68+
# Get data for multiple countries
69+
df = gmd(country=["USA", "CHN", "DEU"])
70+
71+
# Get specific variables
72+
df = gmd(variables=["rGDP", "infl", "unemp"])
73+
74+
# Get raw data for a single variable
75+
df = gmd(variables="rGDP", raw=True)
76+
77+
# List available variables and their descriptions
78+
gmd(vars=True)
79+
80+
# List available countries and their ISO codes
81+
gmd(iso=True)
82+
83+
# Combine parameters
84+
df = gmd(
85+
version="2025_01",
86+
country=["USA", "CHN"],
87+
variables=["rGDP", "unemp", "CPI"]
88+
)
89+
```
90+
91+
## Parameters
92+
- **variables (str or list)**: Variable code(s) to include (e.g., "rGDP" or ["rGDP", "unemp"])
93+
- **country (str or list)**: ISO3 country code(s) (e.g., "SGP" or ["MRT", "SGP"])
94+
- **version (str)**: Dataset version in format 'YYYY_MM' (e.g., '2025_01'). If None or "current", uses the latest version
95+
- **raw (bool)**: If True, download raw data for a single variable
96+
- **iso (bool)**: If True, display list of available countries
97+
- **vars (bool)**: If True, display list of available variables
98+
99+
## Release schedule
100+
| Release Date | Details |
101+
|--------------|-----------------|
102+
| 2025-01-30 | Initial release: 2025_01 |
103+
| 2025-04-01 | 2025_03 |
104+
| 2025-07-01 | 2025_06 |
105+
| 2025-10-01 | 2025_09 |
106+
| 2026-01-01 | 2025_12 |
107+
108+
## Citation
109+
110+
To cite this dataset, please use the following reference:
111+
112+
```bibtex
113+
@techreport{mueller2025global,
114+
title = {The Global Macro Database: A New International Macroeconomic Dataset},
115+
author = {Müller, Karsten and Xu, Chenzi and Lehbib, Mohamed and Chen, Ziliang},
116+
year = {2025},
117+
type = {Working Paper}
118+
}
119+
```
120+
121+
## Acknowledgments
122+
123+
The development of the Global Macro Database would not have been possible without the generous funding provided by the Singapore Ministry of Education (MOE) through the PYP grants (WBS A-0003319-01-00 and A-0003319-02-00), a Tier 1 grant (A-8001749- 00-00), and the NUS Risk Management Institute (A-8002360-00-00). This financial support laid the foundation for the successful completion of this extensive project.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
README.md
2+
setup.py
3+
global_macro_data/__init__.py
4+
global_macro_data/gmd.py
5+
global_macro_data.egg-info/PKG-INFO
6+
global_macro_data.egg-info/SOURCES.txt
7+
global_macro_data.egg-info/dependency_links.txt
8+
global_macro_data.egg-info/requires.txt
9+
global_macro_data.egg-info/top_level.txt
10+
tests/test_gmd.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
pandas
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global_macro_data

global_macro_data/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import os
2-
import requests
3-
import pandas as pd
1+
from .gmd import (
2+
gmd,
3+
get_available_versions,
4+
get_current_version,
5+
list_variables,
6+
list_countries,
7+
VALID_VARIABLES
8+
)
49

5-
# Allowed quarters
6-
VALID_QUARTERS = ["01", "03", "06", "09", "12"]
7-
8-
from .gmd import gmd, find_latest_data
9-
10-
__all__ = ["gmd", "find_latest_data", "VALID_QUARTERS"]
10+
__all__ = [
11+
"gmd",
12+
"get_available_versions",
13+
"get_current_version",
14+
"list_variables",
15+
"list_countries",
16+
"VALID_VARIABLES"
17+
]

0 commit comments

Comments
 (0)