pydeflate 1.4.2__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pydeflate/__init__.py +25 -17
- pydeflate/core/api.py +404 -0
- pydeflate/core/deflator.py +171 -0
- pydeflate/core/exchange.py +237 -0
- pydeflate/core/source.py +54 -0
- pydeflate/deflate/deflators.py +228 -0
- pydeflate/deflate/legacy_deflate.py +109 -0
- pydeflate/exchange/__init__.py +0 -0
- pydeflate/exchange/exchangers.py +147 -0
- pydeflate/pydeflate_config.py +25 -16
- pydeflate/sources/__init__.py +0 -0
- pydeflate/sources/common.py +278 -0
- pydeflate/sources/dac.py +137 -0
- pydeflate/sources/imf.py +203 -0
- pydeflate/sources/world_bank.py +186 -0
- pydeflate/utils.py +55 -22
- {pydeflate-1.4.2.dist-info → pydeflate-2.0.0.dist-info}/LICENSE +1 -1
- pydeflate-2.0.0.dist-info/METADATA +287 -0
- pydeflate-2.0.0.dist-info/RECORD +25 -0
- {pydeflate-1.4.2.dist-info → pydeflate-2.0.0.dist-info}/WHEEL +1 -1
- pydeflate/deflate/deflate.py +0 -324
- pydeflate/deflate/deflator.py +0 -78
- pydeflate/get_data/deflate_data.py +0 -70
- pydeflate/get_data/exchange_data.py +0 -371
- pydeflate/get_data/imf_data.py +0 -76
- pydeflate/get_data/oecd_data.py +0 -146
- pydeflate/get_data/wb_data.py +0 -75
- pydeflate/tools/__init__.py +0 -2
- pydeflate/tools/exchange.py +0 -171
- pydeflate/tools/update_data.py +0 -69
- pydeflate-1.4.2.dist-info/METADATA +0 -305
- pydeflate-1.4.2.dist-info/RECORD +0 -22
- /pydeflate/{get_data → core}/__init__.py +0 -0
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: pydeflate
|
|
3
|
-
Version: 1.4.2
|
|
4
|
-
Summary: Package to convert current prices figures to constant prices and vice versa
|
|
5
|
-
License: MIT
|
|
6
|
-
Author: Jorge Rivera
|
|
7
|
-
Author-email: jorge.rivera@one.org
|
|
8
|
-
Requires-Python: >=3.10,<4.0
|
|
9
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
-
Classifier: Intended Audience :: End Users/Desktop
|
|
11
|
-
Classifier: Intended Audience :: Science/Research
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Natural Language :: English
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Requires-Dist: bblocks (>=1.3)
|
|
19
|
-
Requires-Dist: country-converter (>=1)
|
|
20
|
-
Requires-Dist: numpy (>=1.2)
|
|
21
|
-
Requires-Dist: oda-reader (>=0.2)
|
|
22
|
-
Requires-Dist: pandas (>=2,<3)
|
|
23
|
-
Requires-Dist: pyarrow (>=15.0)
|
|
24
|
-
Requires-Dist: requests (>=2.28.2)
|
|
25
|
-
Requires-Dist: xlrd (>=2.0.1,<3.0.0)
|
|
26
|
-
Description-Content-Type: text/markdown
|
|
27
|
-
|
|
28
|
-
# pydeflate
|
|
29
|
-
|
|
30
|
-
[](https://pypi.python.org/pypi/pydeflate)
|
|
31
|
-
[](https://pydeflate.readthedocs.io/en/latest/?version=latest)
|
|
32
|
-
[](https://github.com/psf/black)
|
|
33
|
-
[](https://pepy.tech/project/pydeflate)
|
|
34
|
-
[](https://codecov.io/gh/jm-rivera/pydeflate)
|
|
35
|
-
|
|
36
|
-
**pydeflate** is a Python package to convert flows data to constant
|
|
37
|
-
prices. This can be done from any source currency to any desired base
|
|
38
|
-
year and currency. **Pydeflate** can also be used to convert constant
|
|
39
|
-
data to current prices and to convert from one currency to another (in
|
|
40
|
-
current and constant prices). Users can choose the source of the
|
|
41
|
-
exchange and deflator/prices data (currently, IMF, World Bank or OECD
|
|
42
|
-
DAC).
|
|
43
|
-
|
|
44
|
-
## Getting started
|
|
45
|
-
|
|
46
|
-
### Installation
|
|
47
|
-
|
|
48
|
-
pydeflate can be installed from PyPI. From the command line:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
|
|
52
|
-
pip install pydeflate
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Basic usage
|
|
57
|
-
|
|
58
|
-
### Current to constant
|
|
59
|
-
|
|
60
|
-
Convert data expressed in current USD prices to constant EUR prices for
|
|
61
|
-
a given base year:
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
from pydeflate import deflate, set_pydeflate_path
|
|
65
|
-
import pandas as pd
|
|
66
|
-
|
|
67
|
-
# Specify where the deflator and exchange data should be saved
|
|
68
|
-
set_pydeflate_path("path/to/data/folder")
|
|
69
|
-
|
|
70
|
-
# example data
|
|
71
|
-
data = {
|
|
72
|
-
'iso_code': ['FRA', 'USA', 'GTM'],
|
|
73
|
-
'year': [2017, 2017, 2017],
|
|
74
|
-
'value': [50, 100, 200]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
# create an example dataframe, in current USD prices
|
|
78
|
-
df = pd.DataFrame.from_dict(data)
|
|
79
|
-
|
|
80
|
-
# convert to EUR 2015 constant prices
|
|
81
|
-
df_constant = deflate(
|
|
82
|
-
df=df,
|
|
83
|
-
base_year=2015,
|
|
84
|
-
deflator_source='world_bank',
|
|
85
|
-
deflator_method='gdp',
|
|
86
|
-
exchange_source="world_bank",
|
|
87
|
-
source_currency="USA", # since data is in USD
|
|
88
|
-
target_currency="EMU", # we want the result in constant EUR
|
|
89
|
-
id_column="iso_code",
|
|
90
|
-
id_type="ISO3", # specifying this is optional in most cases
|
|
91
|
-
date_column="year",
|
|
92
|
-
source_column="value", # where the original data is
|
|
93
|
-
target_col="value_constant", # where the new data will be stored
|
|
94
|
-
)
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
This results in a dataframe containing a new column `value_constant` in
|
|
98
|
-
2015 constant prices. In the background, pydeflate takes into account:
|
|
99
|
-
|
|
100
|
-
- changes in princes, through a gdp deflator in this case
|
|
101
|
-
- changes in exchange rates overtime
|
|
102
|
-
|
|
103
|
-
### Current Local Currency Units to constant in a different currency
|
|
104
|
-
Pydeflate can also handle data that is expressed in local currency
|
|
105
|
-
units. In that case, users can specify `LCU` as the source currency.
|
|
106
|
-
|
|
107
|
-
```python
|
|
108
|
-
from pydeflate import deflate, set_pydeflate_path
|
|
109
|
-
import pandas as pd
|
|
110
|
-
|
|
111
|
-
# Specify where the deflator and exchange data should be saved
|
|
112
|
-
set_pydeflate_path("path/to/data/folder")
|
|
113
|
-
|
|
114
|
-
# example data
|
|
115
|
-
data = {
|
|
116
|
-
'country': ['United Kingdom', 'United Kingdom', 'Japan'],
|
|
117
|
-
'date': [2011, 2015, 2015],
|
|
118
|
-
'value': [100, 100, 100]
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
# create an example dataframe, in current local currency units
|
|
122
|
-
df = pd.DataFrame.from_dict(data)
|
|
123
|
-
|
|
124
|
-
# convert to USD 2018 constant prices
|
|
125
|
-
df_constant = deflate(
|
|
126
|
-
df=df,
|
|
127
|
-
base_year=2018,
|
|
128
|
-
deflator_source='imf',
|
|
129
|
-
deflator_method='pcpi',
|
|
130
|
-
exchange_source="imf",
|
|
131
|
-
source_currency="LCU", # since data is in LCU
|
|
132
|
-
target_currency="USA", # to get data in USD
|
|
133
|
-
id_column="iso_code",
|
|
134
|
-
date_column="date",
|
|
135
|
-
source_col="value",
|
|
136
|
-
target_col="value", # to not create a new column
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Constant to current
|
|
142
|
-
Users can also convert a dataset expressed in constant prices to current
|
|
143
|
-
prices using pydeflate. To avoid introducing errors, users should know
|
|
144
|
-
which methodology/ data was used to create constant prices by the
|
|
145
|
-
original source. The basic usage is the same as before, but the
|
|
146
|
-
`to_current` parameter is set to `True`.
|
|
147
|
-
|
|
148
|
-
For example, to convert DAC data expressed in 2016 USD constant prices
|
|
149
|
-
to current US dollars:
|
|
150
|
-
|
|
151
|
-
```python
|
|
152
|
-
from pydeflate import deflate, set_pydeflate_path
|
|
153
|
-
import pandas as pd
|
|
154
|
-
|
|
155
|
-
# Specify where the deflator and exchange data should be saved
|
|
156
|
-
set_pydeflate_path("path/to/data/folder")
|
|
157
|
-
|
|
158
|
-
# example data
|
|
159
|
-
data = {
|
|
160
|
-
'dac_code': [302, 4, 4],
|
|
161
|
-
'date': [2010, 2016, 2018],
|
|
162
|
-
'value': [100, 100, 100]
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
# create an example dataframe, in current local currency units
|
|
166
|
-
df = pd.DataFrame.from_dict(data)
|
|
167
|
-
|
|
168
|
-
# convert to USD 2018 constant prices
|
|
169
|
-
df_current = deflate(
|
|
170
|
-
df=df,
|
|
171
|
-
base_year=2016,
|
|
172
|
-
deflator_source='oecd_dac',
|
|
173
|
-
deflator_method='dac_deflator',
|
|
174
|
-
exchange_source="oecd_dac",
|
|
175
|
-
source_currency="USA", # since data is in USD constant
|
|
176
|
-
target_currency="LCU", # to get the current LCU figures
|
|
177
|
-
id_column="dac_code",
|
|
178
|
-
id_type="DAC",
|
|
179
|
-
date_column="date",
|
|
180
|
-
source_column="value",
|
|
181
|
-
target_column="value_current",
|
|
182
|
-
to_current=True,
|
|
183
|
-
)
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## Data source and method options
|
|
187
|
-
|
|
188
|
-
In order to convert the data, pydeflate uses data on **price/gdp deflators** and
|
|
189
|
-
**exchange rates**. Each of these data sources can come from the `OECD DAC`,
|
|
190
|
-
`IMF (WEO)` or `World Bank`.
|
|
191
|
-
|
|
192
|
-
For all sources, Exchange rates between two non USD currency pairs are derived from
|
|
193
|
-
the LCU to USD exchange rates selected.
|
|
194
|
-
|
|
195
|
-
### International Monetary Fund World Economic Outlook ("imf")
|
|
196
|
-
|
|
197
|
-
For price/gdp deflators from the IMF, the following options are available (`deflator_method`):
|
|
198
|
-
- `gdp`: in order to use GDP deflators.
|
|
199
|
-
- `pcpi`: in order to use Consumer Price Index data.
|
|
200
|
-
- `pcpie`: to use end-of-period Consumer Price Index data
|
|
201
|
-
(e.g. for December each year).
|
|
202
|
-
|
|
203
|
-
The IMF provides estimates where data is not available, including for several
|
|
204
|
-
years into the future. Using these price deflators, combined with the corresponding
|
|
205
|
-
exchange rates, allows users to convert data to constant prices for future years.
|
|
206
|
-
|
|
207
|
-
For exchange rates, the following options are available from the imf (`exchange_method`):
|
|
208
|
-
- `implied`: to use the exchange rates used by the World Economic Outlook, derived from
|
|
209
|
-
the WEOs data on GDP in US Dollars and Local Currency Units.
|
|
210
|
-
|
|
211
|
-
### World Bank ("world_bank")
|
|
212
|
-
|
|
213
|
-
For price/gdp deflators from the World Bank, the following options are available (`deflator_method`):
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
In terms of price or GDP deflators, pydeflate provides the following
|
|
217
|
-
- `gdp`: in order to use GDP deflators.
|
|
218
|
-
- `gdp_linked`: to use the World Bank's GDP deflator series which
|
|
219
|
-
has been linked to produce a consistent time series to
|
|
220
|
-
counteract breaks in series over time due to changes in base
|
|
221
|
-
years, sources or methodologies.
|
|
222
|
-
- `cpi`: to use Consumer Price Index data
|
|
223
|
-
|
|
224
|
-
For exchange rates, the following options are available from the World Bank (`exchange_method`):
|
|
225
|
-
- `yearly_average`: as used by the World Bank, based on IMF International Financial Statistics data.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
### OECD Development Assistance Committee ("oecd_dac")
|
|
229
|
-
|
|
230
|
-
For price/gdp deflators from the OECD DAC, the following options are available (`deflator_method`):
|
|
231
|
-
|
|
232
|
-
In terms of price or GDP deflators, pydeflate provides the following:
|
|
233
|
-
- `dac_deflator`: in order to use the DAC's own deflator series.
|
|
234
|
-
|
|
235
|
-
For exchange rates, the following options are available from the OECD DAC (`exchange_method`):
|
|
236
|
-
- `implied`: to use the exchange rates used and published by the DAC.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
## Additional features
|
|
241
|
-
|
|
242
|
-
Pydeflate relies on data from the World Bank, IMF and OECD for its
|
|
243
|
-
calculations. This data is updated periodically. If the version of the
|
|
244
|
-
data stored in the user's computer is older than 50 days, pydeflate will
|
|
245
|
-
show a warning on import.
|
|
246
|
-
|
|
247
|
-
Users can always update the underlying data by using:
|
|
248
|
-
|
|
249
|
-
```python
|
|
250
|
-
import pydeflate
|
|
251
|
-
|
|
252
|
-
pydeflate.update_all_data()
|
|
253
|
-
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
Pydeflate also provides users with a tool to exchange figures from one
|
|
257
|
-
currency to another, without applying any deflators. This should only be
|
|
258
|
-
used on numbers expressed in current prices, however.
|
|
259
|
-
|
|
260
|
-
For example, to convert numbers in current Local Currency Units (LCU) to
|
|
261
|
-
current Canadian Dollars:
|
|
262
|
-
|
|
263
|
-
```python
|
|
264
|
-
import pydeflate
|
|
265
|
-
import pandas as pd
|
|
266
|
-
|
|
267
|
-
# example data
|
|
268
|
-
data = {
|
|
269
|
-
'iso_code': ['GBR', 'CAN', 'JPN'],
|
|
270
|
-
'date': [2011, 2015, 2015],
|
|
271
|
-
'value': [100, 100, 100]
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
# create an example dataframe, in current local currency units
|
|
275
|
-
df = pd.DataFrame.from_dict(data)
|
|
276
|
-
|
|
277
|
-
# convert to USD 2018 constant prices
|
|
278
|
-
df_can = pydeflate.exchange(
|
|
279
|
-
df=df,
|
|
280
|
-
source_currency="LCU", # since data is in LCU
|
|
281
|
-
target_currency="CAN", # to get data in Canadian Dollars
|
|
282
|
-
rates_source='imf',
|
|
283
|
-
value_column='value',
|
|
284
|
-
target_column='value_CAN',
|
|
285
|
-
id_column="iso_code",
|
|
286
|
-
id_type="ISO3",
|
|
287
|
-
date_column="date",
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### Credits
|
|
293
|
-
|
|
294
|
-
This package relies on data from the following sources:
|
|
295
|
-
|
|
296
|
-
- OECD DAC: <https://www.oecd.org/dac/> (Official Development
|
|
297
|
-
assistance data (DAC1), DAC deflators, and exchange rates used by
|
|
298
|
-
the DAC)
|
|
299
|
-
- IMF World Economic Outlook:
|
|
300
|
-
<https://www.imf.org/en/Publications/WEO> (GDP and price deflators)
|
|
301
|
-
- World Bank DataBank: <https://databank.worldbank.org/home.aspx>
|
|
302
|
-
(exchange rates, GDP and price deflators)
|
|
303
|
-
|
|
304
|
-
This data is provided based on the terms and conditions set by the
|
|
305
|
-
original sources.
|
pydeflate-1.4.2.dist-info/RECORD
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
pydeflate/.pydeflate_data/README.md,sha256=atNtUL9dD8G184YSd6juFib8TgEQBcSLogiz99APPVs,25
|
|
2
|
-
pydeflate/__init__.py,sha256=pMVw7I5OMmlsIKt4ndVFOfSKnIyZHcITLCF_Rd1upKs,817
|
|
3
|
-
pydeflate/deflate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
pydeflate/deflate/deflate.py,sha256=hSlhuJi1YsemvvRBFgJog1oQI8lqkJ8nBn6PoufR7uk,11850
|
|
5
|
-
pydeflate/deflate/deflator.py,sha256=8nX_E1WPfY1ej8lfoLyOxnWNX0kW9khQIxa_QlrRm4A,2684
|
|
6
|
-
pydeflate/get_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
pydeflate/get_data/deflate_data.py,sha256=tZuxT38xRBXXaPSpLFtrEL5iz2TO7LFs8lNG2E64Ew0,2285
|
|
8
|
-
pydeflate/get_data/exchange_data.py,sha256=bXMiYlHxqKqyZvkKhogFXOXVCmDL-rF6TNraVd3daNA,12248
|
|
9
|
-
pydeflate/get_data/imf_data.py,sha256=mEeqC1DfZ8kPn6fUjaFVNX8VfuSHtARcrqBVLnxwrRs,2693
|
|
10
|
-
pydeflate/get_data/oecd_data.py,sha256=QMHpCjpedlzoWpHaMk64vVIzuoAiJ99gXf0l1siLR3I,4492
|
|
11
|
-
pydeflate/get_data/wb_data.py,sha256=21L1ALmxL0Y-KjoDLJI7EUsDt8igBRnDjCro4lKi0l0,2103
|
|
12
|
-
pydeflate/pydeflate_config.py,sha256=wY9RQ2UVmCekusHeKUFmryA1DzWanP9BuOPDFPyva-4,894
|
|
13
|
-
pydeflate/settings/emu.json,sha256=BIvbiMUeHUtCESR3sMcBNrS028yp2YraCJdhDJGvAAo,133
|
|
14
|
-
pydeflate/settings/oecd_codes.json,sha256=jAKI1EgQP4rttjoG3Z-44r1tUJrIEzPCZF5V2aboQhE,911
|
|
15
|
-
pydeflate/tools/__init__.py,sha256=gbUXYeGrcrqcOc70BjFtxHtBnwSqor-SlWYgZjypEOA,47
|
|
16
|
-
pydeflate/tools/exchange.py,sha256=q8E4IsZcI015UjIwLXWl7d9PiqgHTFyalRm2fURfc3Y,5465
|
|
17
|
-
pydeflate/tools/update_data.py,sha256=nB05Y0ZEZ2WcYPjOR_O9QHdvvNy0JkWc1z_sH71U2lY,2109
|
|
18
|
-
pydeflate/utils.py,sha256=p0k3RzJBlqHQGIYWH3woAINRAPpfyM0mRu_cB29QS54,1573
|
|
19
|
-
pydeflate-1.4.2.dist-info/LICENSE,sha256=HwwzYp5BG8nNjP8ZgcxnE-fva8_Yx1ss7PZne73J9IE,1070
|
|
20
|
-
pydeflate-1.4.2.dist-info/METADATA,sha256=z7_PxzVh0nVu5Pw9Ssn_cHMzSm3fR2FdfhlH0FN7ZKk,9994
|
|
21
|
-
pydeflate-1.4.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
22
|
-
pydeflate-1.4.2.dist-info/RECORD,,
|
|
File without changes
|