Skip to content

Commit

Permalink
changed deprecation warning to decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinGebhart committed Nov 4, 2024
1 parent 685b6c8 commit bfef378
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
25 changes: 12 additions & 13 deletions climada/engine/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import numpy as np
import pandas as pd
import xlsxwriter
from deprecation import deprecated
from pyproj import CRS as pyprojCRS
from rasterio.crs import CRS as rasterioCRS # pylint: disable=no-name-in-module
from scipy import sparse
Expand Down Expand Up @@ -595,14 +596,14 @@ def local_exceedance_impact(

return gdf, label, column_label

@deprecated(
details="The use of Impact.local_exceedance_imp is deprecated. Use "
"Impact.local_exceedance_impact instead. Some errors in the previous calculation "
"in Impact.local_exceedance_imp have been corrected. To reproduce data with the "
"previous calculation, use CLIMADA v5.0.0 or less."
)
def local_exceedance_imp(self, return_periods=(25, 50, 100, 250)):
"""This function is deprecated, use Impact.local_exceedance_impact instead."""
LOGGER.warning(
"The use of Impact.local_exceedance_imp is deprecated. Use "
"Impact.local_exceedance_impact instead. Some errors in the previous calculation "
"in Impact.local_exceedance_imp have been corrected. To reproduce data with the "
"previous calculation, use CLIMADA v5.0.0 or less."
)

return (

Check warning on line 608 in climada/engine/impact.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered line

Line 608 is not covered by tests
self.local_exceedance_impact(return_periods)[0]
Expand Down Expand Up @@ -1001,7 +1002,10 @@ def plot_basemap_impact_exposure(

return axis

# TODO: replace with plot_from_gdf()
@deprecated(
details="The use of Impact.plot_rp_imp is deprecated."
"Use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead."
)
def plot_rp_imp(
self,
return_periods=(25, 50, 100, 250),
Expand All @@ -1013,13 +1017,8 @@ def plot_rp_imp(
"""
This function is deprecated, use Impact.local_exceedance_impact and
util.plot.plot_from_gdf instead.
"""
LOGGER.warning(
"The use of Impact.plot_rp_imp is deprecated."
"Use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead."
)
"""Compute and plot exceedance impact maps for different return periods.
Compute and plot exceedance impact maps for different return periods.
Calls local_exceedance_imp.
Parameters
Expand Down
13 changes: 7 additions & 6 deletions climada/hazard/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import geopandas as gpd
import numpy as np
from deprecation import deprecated
from pathos.pools import ProcessPool as Pool
from scipy import sparse

Expand Down Expand Up @@ -584,14 +585,14 @@ def local_exceedance_intensity(

return gdf, label, column_label

@deprecated(
details="The use of Hazard.local_exceedance_inten is deprecated. Use "
"Hazard.local_exceedance_intensity instead. Some errors in the previous calculation "
"in Hazard.local_exceedance_inten have been corrected. To reproduce data with the "
"previous calculation, use CLIMADA v5.0.0 or less."
)
def local_exceedance_inten(self, return_period=(25, 50, 100, 250)):
"""This function is deprecated, use Hazard.local_exceedance_intensity instead."""
LOGGER.warning(
"The use of Hazard.local_exceedance_inten is deprecated. Use "
"Hazard.local_exceedance_intensity instead. Some errors in the previous calculation "
"in Hazard.local_exceedance_inten have been corrected. To reproduce data with the "
"previous calculation, use CLIMADA v5.0.0 or less."
)
return (

Check warning on line 596 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered line

Line 596 is not covered by tests
self.local_exceedance_intensity(return_period)[0]
.values[:, 1:]
Expand Down
13 changes: 6 additions & 7 deletions climada/hazard/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import matplotlib.pyplot as plt
import numpy as np
from deprecation import deprecated

import climada.util.plot as u_plot

Expand All @@ -36,7 +37,10 @@ class HazardPlot:
Contains all plotting methods of the Hazard class
"""

# TODO depreciating warning, to be replaced with plot_from_gdf
@deprecated(
details="The use of Hazard.plot_rp_intensity is deprecated."
"Use Hazard.local_exceedance_intensity and util.plot.plot_from_gdf instead."
)
def plot_rp_intensity(

Check warning on line 44 in climada/hazard/plot.py

View check run for this annotation

Jenkins - WCR / Pylint

too-many-positional-arguments

LOW: Too many positional arguments (6/5)
Raw output
no description found
self,
return_periods=(25, 50, 100, 250),
Expand All @@ -49,13 +53,8 @@ def plot_rp_intensity(
"""
This function is deprecated,
use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead.
"""
LOGGER.warning(
"The use of Hazard.plot_rp_intensity is deprecated."
"Use Hazard.local_exceedance_intensity and util.plot.plot_from_gdf instead."
)
"""Compute and plot hazard exceedance intensity maps for different
Compute and plot hazard exceedance intensity maps for different
return periods. Calls local_exceedance_inten.
Parameters
Expand Down

0 comments on commit bfef378

Please sign in to comment.