Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-rivera committed Nov 9, 2024
1 parent 8c735ff commit 92760af
Show file tree
Hide file tree
Showing 10 changed files with 668 additions and 1,110 deletions.
1,658 changes: 573 additions & 1,085 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions pydeflate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__author__ = """Jorge Rivera"""
__version__ = "1.3.10"

from pydeflate.pydeflate_config import setup_logger


def set_pydeflate_path(path):
from pathlib import Path
Expand All @@ -12,6 +14,10 @@ def set_pydeflate_path(path):
PYDEFLATE_PATHS.data = Path(path).resolve()


logger = setup_logger("pydeflate")


__all__ = [
"set_pydeflate_path",
"logger",
]
10 changes: 10 additions & 0 deletions pydeflate/deflate/deflators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def dac_deflate():
return NotImplemented


def wb_deflate():
return NotImplemented


def imf_deflate():
return NotImplemented
56 changes: 56 additions & 0 deletions pydeflate/deflate/legacy_deflate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import warnings

import pandas as pd
from pandas.util._decorators import deprecate_kwarg


@deprecate_kwarg(old_arg_name="method", new_arg_name="deflator_method")
@deprecate_kwarg(old_arg_name="source", new_arg_name="deflator_source")
@deprecate_kwarg(old_arg_name="iso_column", new_arg_name="id_column")
@deprecate_kwarg(old_arg_name="source_col", new_arg_name="source_column")
@deprecate_kwarg(old_arg_name="target_col", new_arg_name="target_column")
def deflate(
df: pd.DataFrame,
base_year: int,
deflator_source: str,
deflator_method: str,
exchange_source: str,
exchange_method: str,
source_currency: str = "USA",
target_currency: str = "USA",
id_column: str = "iso_code",
id_type: str = "ISO3",
date_column: str = "date",
source_column: str = "value",
target_column: str = "value",
to_current: bool = False,
) -> pd.DataFrame:
"""DEPRECATED: Use pydeflate's updated API for deflation adjustments.
This legacy function is provided for backwards compatibility only.
Please refer to the latest documentation for using pydeflate's updated API.
Args:
df (pd.DataFrame): DataFrame with flow data to be deflated.
base_year (int): Target year for base value adjustments.
deflator_source (str): Source of deflator data, e.g., 'oecd_dac', 'wb', 'imf'.
deflator_method (str): Method for deflator calculation, e.g., 'gdp', 'cpi'.
exchange_source (str): Source for exchange rates.
exchange_method (str): Method for exchange rate calculation.
source_currency (str): ISO3 code for the source currency.
target_currency (str): ISO3 code for the target currency.
id_column (str): Column for entity identifiers, e.g., 'iso_code'.
id_type (str): Type of ID classification; default is 'ISO3'.
date_column (str): Column for date information.
source_column (str): Column with original monetary values.
target_column (str): Column to store deflated values.
to_current (bool): If True, convert to current prices.
Returns:
pd.DataFrame: DataFrame with deflated values.
"""
warnings.warn(
"The `deflate` function is deprecated and will be removed in future versions. "
"Please check the latest documentation for updated methods.",
DeprecationWarning,
)
20 changes: 10 additions & 10 deletions pydeflate/pydeflate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ def setup_logger(name) -> logging.Logger:
logger_ = logging.getLogger(name)
logger_.setLevel(logging.INFO)

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
# Only add handlers if the logger has none to avoid duplication
if not logger_.hasHandlers():
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)

formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s:\n %(message)s"
)
console_handler.setFormatter(formatter)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s:\n %(message)s"
)
console_handler.setFormatter(formatter)

logger_.addHandler(console_handler)
logger_.addHandler(console_handler)
logger_.propagate = False

return logger_


logger = setup_logger("pydeflate")
3 changes: 2 additions & 1 deletion pydeflate/sources/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import pandas as pd
from hdx.location.country import Country

from pydeflate.pydeflate_config import logger, PYDEFLATE_PATHS
from pydeflate import logger
from pydeflate.pydeflate_config import PYDEFLATE_PATHS

AvailableDeflators = Literal["NGDP_D", "NGDP_DL", "PCPI", "PCPIE"]

Expand Down
3 changes: 2 additions & 1 deletion pydeflate/sources/imf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pandas as pd
from imf_reader import weo

from pydeflate.pydeflate_config import PYDEFLATE_PATHS, logger
from pydeflate import logger
from pydeflate.pydeflate_config import PYDEFLATE_PATHS
from pydeflate.sources.common import (
today,
add_pydeflate_iso3,
Expand Down
3 changes: 2 additions & 1 deletion pydeflate/sources/world_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pandas as pd
import wbgapi as wb

from pydeflate.pydeflate_config import PYDEFLATE_PATHS, logger
from pydeflate import logger
from pydeflate.pydeflate_config import PYDEFLATE_PATHS
from pydeflate.sources.common import (
enforce_pyarrow_types,
today,
Expand Down
3 changes: 2 additions & 1 deletion pydeflate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import pandas as pd

from pydeflate.pydeflate_config import PYDEFLATE_PATHS, logger
from pydeflate import logger
from pydeflate.pydeflate_config import PYDEFLATE_PATHS
from pydeflate.sources.common import enforce_pyarrow_types


Expand Down
16 changes: 5 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@ classifiers=[
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
]

packages = [
{ include = "pydeflate" },
]

[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.26"
python = ">=3.10, <4.0"
pandas = "^2"
beautifulsoup4 = "^4.12"
weo = "^0.7.4"
xlrd = "^2.0.1"
country-converter = "^1"
requests = "^2.28.2"
pyarrow = ">14"
bblocks = "^1.2.1"
imf-reader = "^1.1.0"
hdx-python-country = "^3.8.1"
oda-reader = "^1.0.0"
wbgapi = "^1.0.12"
country-converter = "^1.2"


[tool.poetry.dev-dependencies]
bump2version = "^1.0.1"
black = "^24"
pytest = "^7.2.1"
pytest-cov = "^4.0.0"
pytest-mock = "^3.10.0"


[build-system]
Expand Down

0 comments on commit 92760af

Please sign in to comment.