Skip to content

Commit

Permalink
Merge pull request #237 from jGaboardi/deprecate_by_cols
Browse files Browse the repository at this point in the history
future warn for .by_col() methods
  • Loading branch information
sjsrey authored May 27, 2023
2 parents 7f3b9cf + c95380f commit 17c5f00
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
7 changes: 7 additions & 0 deletions esda/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ def __pseudop(self, sim, g):
def by_col(
cls, df, cols, w=None, inplace=False, pvalue="sim", outvals=None, **stat_kws
):

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

return _univariate_handler(
df,
cols,
Expand Down
9 changes: 9 additions & 0 deletions esda/geary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
__author__ = "Serge Rey <[email protected]> "

import warnings

import numpy as np
import scipy.stats as stats
from libpysal import weights
Expand Down Expand Up @@ -224,6 +226,13 @@ def by_col(
Technical details and derivations can be found in :cite:`cliff81`.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

return _univariate_handler(
df,
cols,
Expand Down
20 changes: 17 additions & 3 deletions esda/getisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ def by_col(
the relevant columns attached.
"""

msg = (
"The `.by_cols()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

return _univariate_handler(
df,
cols,
Expand Down Expand Up @@ -498,9 +505,9 @@ def calc(self):
expected_value = cardinality / N

expected_variance = cardinality * (N - cardinality)
expected_variance /= (N - 1)
expected_variance *= (1 / N**2)
expected_variance *= (empirical_variance / (empirical_mean**2))
expected_variance /= N - 1
expected_variance *= 1 / N**2
expected_variance *= empirical_variance / (empirical_mean**2)

z_scores = (statistic - expected_value) / np.sqrt(expected_variance)

Expand Down Expand Up @@ -552,6 +559,13 @@ def by_col(
the relevant columns attached.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

return _univariate_handler(
df,
cols,
Expand Down
9 changes: 9 additions & 0 deletions esda/join_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""
__author__ = "Sergio J. Rey <[email protected]> , Luc Anselin <[email protected]>"

import warnings

import numpy as np
import pandas as pd
from scipy.stats import chi2, chi2_contingency
Expand Down Expand Up @@ -288,6 +290,13 @@ def by_col(
dataframe with the relevant columns attached.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

if outvals is None:
outvals = []
outvals.extend(["bb", "p_sim_bw", "p_sim_bb"])
Expand Down
35 changes: 35 additions & 0 deletions esda/smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"Serge Rey <[email protected]"
)

import warnings
from functools import reduce

from libpysal.cg import (
Expand Down Expand Up @@ -653,6 +654,13 @@ def by_col(cls, df, e, b, inplace=False, **kwargs):
a copy of `df` containing the columns. Or, if `inplace`, this returns
None, but implicitly adds columns to `df`.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

if not inplace:
new = df.copy()
cls.by_col(new, e, b, inplace=True, **kwargs)
Expand Down Expand Up @@ -848,6 +856,13 @@ def by_col(cls, df, e, b, w=None, inplace=False, **kwargs):
a copy of `df` containing the columns. Or, if `inplace`, this returns
None, but implicitly adds columns to `df`.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

if not inplace:
new = df.copy()
cls.by_col(new, e, b, w=w, inplace=True, **kwargs)
Expand Down Expand Up @@ -1240,6 +1255,13 @@ def by_col(cls, df, e, b, w=None, s=None, **kwargs):
a copy of `df` containing the columns. Or, if `inplace`, this returns
None, but implicitly adds columns to `df`.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

if s is None:
raise ValueError("Standard population variable 's' must be supplied.")
import pandas as pd
Expand Down Expand Up @@ -1660,6 +1682,13 @@ def by_col(cls, df, e, b, x_grid, y_grid, geom_col="geometry", **kwargs):
coordinates of the grid cells and the rates associated with those grid
cells.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

import pandas as pd

# prep for application over multiple event/population pairs
Expand Down Expand Up @@ -2123,6 +2152,12 @@ def by_col(cls, df, e, b, t=None, geom_col="geometry", inplace=False, **kwargs):
`df` is modified in place.
"""

msg = (
"The `.by_col()` methods are deprecated and will be "
"removed in a future version of `esda`."
)
warnings.warn(msg, FutureWarning)

if not inplace:
new = df.copy()
cls.by_col(new, e, b, t=t, geom_col=geom_col, inplace=True, **kwargs)
Expand Down

0 comments on commit 17c5f00

Please sign in to comment.