pydeflate 2.1.0__py3-none-any.whl → 2.1.2__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 CHANGED
@@ -1,5 +1,5 @@
1
1
  __author__ = """Jorge Rivera"""
2
- __version__ = "2.1.0"
2
+ __version__ = "2.1.2"
3
3
 
4
4
  from pydeflate.deflate.deflators import (
5
5
  oecd_dac_deflate,
pydeflate/core/api.py CHANGED
@@ -176,6 +176,8 @@ class BaseExchange:
176
176
  pydeflate_data=self.pydeflate_data,
177
177
  entity_column=entity_column,
178
178
  ix=self._idx,
179
+ source_codes=self._idx[-1] == "pydeflate_entity_code",
180
+ dac=self.exchange_rates.source.name == "DAC",
179
181
  )
180
182
 
181
183
  # store unmatched data
@@ -365,6 +367,9 @@ class BaseDeflate:
365
367
  pydeflate_data=self.pydeflate_data,
366
368
  entity_column=entity_column,
367
369
  ix=self._idx,
370
+ source_codes=self.use_source_codes,
371
+ dac=self.exchange_deflator.source.name == "DAC"
372
+ or self.price_deflator.source.name == "DAC",
368
373
  )
369
374
 
370
375
  # store unmatched data
@@ -59,7 +59,10 @@ def _match_regex_to_iso3(
59
59
  matches = {}
60
60
 
61
61
  for match in to_match:
62
- match_ = country.get_iso3_country_code_fuzzy(match)[0]
62
+ try:
63
+ match_ = country.get_iso3_country_code_fuzzy(match)[0]
64
+ except:
65
+ match_ = None
63
66
  matches[match] = match_
64
67
  if match_ is None and match not in additional_mapping:
65
68
  logger.debug(f"No ISO3 match found for {match}")
pydeflate/utils.py CHANGED
@@ -51,21 +51,68 @@ def create_pydeflate_year(
51
51
  return data
52
52
 
53
53
 
54
+ def _use_implied_dac_rates(
55
+ data: pd.DataFrame,
56
+ pydeflate_data: pd.DataFrame,
57
+ ix: list[str],
58
+ entity_column: str,
59
+ source_codes: bool,
60
+ ) -> pd.DataFrame:
61
+ """When rates are missing for entities in DAC data, the correct behaviour is to use
62
+ the DAC overall rates"""
63
+
64
+ # Assign the DAC code to a temporary column
65
+ data.loc[
66
+ lambda d: ~d[f"temp_{entity_column}"].isin(pydeflate_data[ix[-1]].unique()),
67
+ f"temp_{entity_column}",
68
+ ] = (
69
+ 20001 if source_codes else "DAC"
70
+ )
71
+
72
+ # Log the fact that implied rates are being used
73
+ flag_missing_pydeflate_data(
74
+ unmatched_data=data.loc[
75
+ lambda d: ~d[f"{entity_column}"].isin(pydeflate_data[ix[-1]].unique())
76
+ ],
77
+ entity_column=entity_column,
78
+ year_column="pydeflate_year",
79
+ using_implied=True,
80
+ )
81
+
82
+ return data
83
+
84
+
54
85
  def merge_user_and_pydeflate_data(
55
86
  data: pd.DataFrame,
56
87
  pydeflate_data: pd.DataFrame,
57
88
  entity_column: str,
58
89
  ix: list[str],
90
+ source_codes: bool = True,
91
+ dac: bool = False,
59
92
  ) -> pd.DataFrame:
60
- return data.merge(
93
+
94
+ data[f"temp_{entity_column}"] = data[entity_column]
95
+
96
+ if dac:
97
+ data = _use_implied_dac_rates(
98
+ data=data,
99
+ pydeflate_data=pydeflate_data,
100
+ ix=ix,
101
+ entity_column=entity_column,
102
+ source_codes=source_codes,
103
+ )
104
+
105
+ df_ = data.merge(
61
106
  pydeflate_data,
62
107
  how="outer",
63
- left_on=["pydeflate_year", entity_column],
108
+ left_on=["pydeflate_year", f"temp_{entity_column}"],
64
109
  right_on=ix,
65
110
  suffixes=("", "_pydeflate"),
66
111
  indicator=True,
67
112
  ).pipe(enforce_pyarrow_types)
68
113
 
114
+ return df_.drop(columns=[f"temp_{entity_column}"])
115
+
69
116
 
70
117
  def get_unmatched_pydeflate_data(
71
118
  merged_data: pd.DataFrame,
@@ -86,7 +133,10 @@ def get_matched_pydeflate_data(
86
133
 
87
134
 
88
135
  def flag_missing_pydeflate_data(
89
- unmatched_data: pd.DataFrame, entity_column: str, year_column: str
136
+ unmatched_data: pd.DataFrame,
137
+ entity_column: str,
138
+ year_column: str,
139
+ using_implied: bool = False,
90
140
  ):
91
141
  """Flag data which is present in the input data but missing in pydeflate's data."""
92
142
  if unmatched_data.empty:
@@ -102,4 +152,9 @@ def flag_missing_pydeflate_data(
102
152
  missing_str = "\n".join(f"{entity}: {years}" for entity, years in missing.items())
103
153
 
104
154
  # log all missing data
105
- logger.info(f"Missing exchange data for:\n{missing_str}")
155
+ message = (
156
+ "Using DAC members' rates (given missing data) for:"
157
+ if using_implied
158
+ else "Missing exchange data for:"
159
+ )
160
+ logger.info(f"{message}\n{missing_str}")
@@ -1,26 +1,23 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: pydeflate
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Package to convert current prices figures to constant prices and vice versa
5
5
  License: MIT
6
6
  Author: Jorge Rivera
7
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
8
+ Requires-Python: >=3.10, <4.0
12
9
  Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Natural Language :: English
14
10
  Classifier: Programming Language :: Python :: 3
15
11
  Classifier: Programming Language :: Python :: 3.10
16
12
  Classifier: Programming Language :: Python :: 3.11
17
13
  Classifier: Programming Language :: Python :: 3.12
18
14
  Classifier: Programming Language :: Python :: 3.13
19
- Requires-Dist: hdx-python-country (>=3.8.1,<4.0.0)
20
- Requires-Dist: imf-reader (>=1.1.0,<2.0.0)
21
- Requires-Dist: oda-reader (>=1.0.0,<2.0.0)
22
- Requires-Dist: pandas (>=2,<3)
23
- Requires-Dist: pyarrow (>14)
15
+ Requires-Dist: hdx-python-country (>=3.8,<4.0.0)
16
+ Requires-Dist: imf-reader (>=1.2.0,<2.0.0)
17
+ Requires-Dist: oda-reader (>=1.0.5,<2.0.0)
18
+ Requires-Dist: pandas (>=2.2.3,<3.0.0)
19
+ Requires-Dist: pyarrow (>=14.0)
20
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
24
21
  Requires-Dist: wbgapi (>=1.0.12,<2.0.0)
25
22
  Description-Content-Type: text/markdown
26
23
 
@@ -1,7 +1,7 @@
1
1
  pydeflate/.pydeflate_data/README.md,sha256=atNtUL9dD8G184YSd6juFib8TgEQBcSLogiz99APPVs,25
2
- pydeflate/__init__.py,sha256=1e1NQwoAS1lx5d3w3O_5n7v4NKf3PibDlvCBvsnQZFk,1013
2
+ pydeflate/__init__.py,sha256=LFrWXqC2bHJU0QJSUOUtWPW_YJ3e31Jg54zGXZUt0jc,1013
3
3
  pydeflate/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- pydeflate/core/api.py,sha256=DATtc-DIo38bziP8S-XLsGn1J709v3vnNYMy5poLx3c,14397
4
+ pydeflate/core/api.py,sha256=mD5zhGlAIvlpT6KcmrHW5rmYwtEq5x2Pqo-jQCQMGpo,14687
5
5
  pydeflate/core/deflator.py,sha256=Ax3dmOF3tYRZnkIfFvMMo3SOLgAJHkXSmA-OtIUZkp0,5932
6
6
  pydeflate/core/exchange.py,sha256=br6RVgTGa7LW09XemUJZ4Koazf65zuXPQKYKGhS6ROM,8535
7
7
  pydeflate/core/source.py,sha256=n603ocgGjthXNcBWwgADkefxWmSFuN77Km9Z0T2zpIg,2027
@@ -14,12 +14,12 @@ pydeflate/pydeflate_config.py,sha256=5s4SLJf5is5XcUgJHDRx4f27pPiaVh0H2BL8w9QjW0k
14
14
  pydeflate/settings/emu.json,sha256=BIvbiMUeHUtCESR3sMcBNrS028yp2YraCJdhDJGvAAo,133
15
15
  pydeflate/settings/oecd_codes.json,sha256=jAKI1EgQP4rttjoG3Z-44r1tUJrIEzPCZF5V2aboQhE,911
16
16
  pydeflate/sources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- pydeflate/sources/common.py,sha256=TvoN3jnqn0xXNuxM52vvgSLA5WRGX8PUD-b5YH6S7GE,9882
17
+ pydeflate/sources/common.py,sha256=aQ0p8fOccFZnq93tTmHJbPyF13BJbZep8QP-yzizfcE,9941
18
18
  pydeflate/sources/dac.py,sha256=ngFiApGZ_tIQg74ogGVTIbGUA0efnF1SYwfUuqGofOQ,3791
19
19
  pydeflate/sources/imf.py,sha256=10vc8xhNJvANb7RDD1WFn9oaZ8g53yUV5LxCQCz6ImM,6337
20
20
  pydeflate/sources/world_bank.py,sha256=uMHidFVgEpj1HVUnNhIZV-rV64hsCBV9ZAbYKk6H0Vw,9333
21
- pydeflate/utils.py,sha256=VFY-xcpnh7wQ1WGxA2sniJmNlzEasRr4UzNWbdBz2C0,2535
22
- pydeflate-2.1.0.dist-info/LICENSE,sha256=q5tm9mQxwSbV5Ivvjxs7MMqBgan6DM8I4r4irPvmqZM,1075
23
- pydeflate-2.1.0.dist-info/METADATA,sha256=Ou2ipM2d6xpysEoLxYCvUc9YoNGVCUiIjOs-RWWmYOQ,12582
24
- pydeflate-2.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
25
- pydeflate-2.1.0.dist-info/RECORD,,
21
+ pydeflate/utils.py,sha256=tJBd271WzZxVhW9ZMiIRHR0fZWr_MagAYLdmXXaUY3M,3983
22
+ pydeflate-2.1.2.dist-info/LICENSE,sha256=q5tm9mQxwSbV5Ivvjxs7MMqBgan6DM8I4r4irPvmqZM,1075
23
+ pydeflate-2.1.2.dist-info/METADATA,sha256=1uagncn8PNwpR-ID4-S1CC2cv4ybE6AbpDndTjKM6zo,12437
24
+ pydeflate-2.1.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
25
+ pydeflate-2.1.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any