Skip to content

Commit

Permalink
Use pyupgrade *.py --py310-plus (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelvallat authored Jun 4, 2023
1 parent 5c5f61a commit faad22a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pingouin/bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def fun(g, r, n):
)

integr = quad(fun, 0, np.inf, args=(r, n))[0]
bf10 = np.sqrt((n / 2)) / gamma(1 / 2) * integr
bf10 = np.sqrt(n / 2) / gamma(1 / 2) * integr

else:
# Ly et al, 2016. Analytical solution.
Expand Down
2 changes: 1 addition & 1 deletion pingouin/contingency.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def chi2_independence(data, x, y, correction=True):
# All count frequencies should be at least 5
for df, name in zip([observed, expected], ["observed", "expected"]):
if (df < 5).any(axis=None):
warnings.warn("Low count on {} frequencies.".format(name))
warnings.warn(f"Low count on {name} frequencies.")

dof = float(expected.size - sum(expected.shape) + expected.ndim - 1)

Expand Down
6 changes: 3 additions & 3 deletions pingouin/effsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def convert_effsize(ef, input_type, output_type, nx=None, ny=None):
# Check input and output type
for inp in [it, ot]:
if not _check_eftype(inp):
err = "Could not interpret input '{}'".format(inp)
err = f"Could not interpret input '{inp}'"
raise ValueError(err)
if it not in ["pointbiserialr", "cohen"]:
raise ValueError("Input type must be 'cohen' or 'pointbiserialr'")
Expand Down Expand Up @@ -768,7 +768,7 @@ def compute_effsize(x, y, paired=False, eftype="cohen"):
"""
# Check arguments
if not _check_eftype(eftype):
err = "Could not interpret input '{}'".format(eftype)
err = f"Could not interpret input '{eftype}'"
raise ValueError(err)

x = np.asarray(x)
Expand Down Expand Up @@ -862,7 +862,7 @@ def compute_effsize_from_t(tval, nx=None, ny=None, N=None, eftype="cohen"):
0.7487767802667672
"""
if not _check_eftype(eftype):
err = "Could not interpret input '{}'".format(eftype)
err = f"Could not interpret input '{eftype}'"
raise ValueError(err)

if not isinstance(tval, float):
Expand Down
3 changes: 1 addition & 2 deletions pingouin/pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,8 +1324,7 @@ def traverse(o, tree_types=(list, tuple)):
"""
if isinstance(o, tree_types):
for value in o:
for subvalue in traverse(value, tree_types):
yield subvalue
yield from traverse(value, tree_types)
else:
yield o

Expand Down
10 changes: 5 additions & 5 deletions pingouin/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def rm_anova(

# If required, apply Greenhouse-Geisser correction for sphericity
if correction:
corr_ddof1, corr_ddof2 = [np.maximum(d * eps, 1.0) for d in (ddof1, ddof2)]
corr_ddof1, corr_ddof2 = (np.maximum(d * eps, 1.0) for d in (ddof1, ddof2))
p_corr = f(corr_ddof1, corr_ddof2).sf(fval)

# Create output dataframe
Expand Down Expand Up @@ -781,9 +781,9 @@ def rm_anova2(data=None, dv=None, within=None, subject=None, effsize="ng2"):
eps_ab = epsilon(data_piv, correction="gg")

# Greenhouse-Geisser correction
df_a_c, df_as_c = [np.maximum(d * eps_a, 1.0) for d in (df_a, df_as)]
df_b_c, df_bs_c = [np.maximum(d * eps_b, 1.0) for d in (df_b, df_bs)]
df_ab_c, df_abs_c = [np.maximum(d * eps_ab, 1.0) for d in (df_ab, df_abs)]
df_a_c, df_as_c = (np.maximum(d * eps_a, 1.0) for d in (df_a, df_as))
df_b_c, df_bs_c = (np.maximum(d * eps_b, 1.0) for d in (df_b, df_bs))
df_ab_c, df_abs_c = (np.maximum(d * eps_ab, 1.0) for d in (df_ab, df_abs))
p_a_corr = f(df_a_c, df_as_c).sf(f_a)
p_b_corr = f(df_b_c, df_bs_c).sf(f_b)
p_ab_corr = f(df_ab_c, df_abs_c).sf(f_ab)
Expand Down Expand Up @@ -1714,7 +1714,7 @@ def ancova(data=None, dv=None, between=None, covar=None, effsize="np2"):
assert dv not in ["C", "Q"], "`dv` must not be 'C' or 'Q'."
assert between not in ["C", "Q"], "`between` must not be 'C' or 'Q'."
assert all(c not in ["C", "Q"] for c in covar), "`covar` must not contain 'C' or 'Q'."
formula = "Q('%s') ~ C(Q('%s'))" % (dv, between)
formula = f"Q('{dv}') ~ C(Q('{between}'))"
for c in covar:
formula += " + Q('%s')" % (c)
model = ols(formula, data=data).fit()
Expand Down
2 changes: 1 addition & 1 deletion pingouin/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ def plot_rm_corr(
assert x not in ["C", "Q"], "`x` must not be 'C' or 'Q'."
assert y not in ["C", "Q"], "`y` must not be 'C' or 'Q'."
assert subject not in ["C", "Q"], "`subject` must not be 'C' or 'Q'."
formula = "Q('%s') ~ C(Q('%s')) + Q('%s')" % (y, subject, x)
formula = f"Q('{y}') ~ C(Q('{subject}')) + Q('{x}')"
model = ols(formula, data=data).fit()

# Fitted values
Expand Down
2 changes: 1 addition & 1 deletion pingouin/reliability.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def intraclass_corr(data=None, targets=None, raters=None, ratings=None, nan_poli
u3 = (f3u - 1) / (f3u + (k - 1))
# Case 2
fj = msj / mse
vn = df2kd * ((k * icc2 * fj + n * (1 + (k - 1) * icc2) - k * icc2)) ** 2
vn = df2kd * (k * icc2 * fj + n * (1 + (k - 1) * icc2) - k * icc2) ** 2
vd = df1 * k**2 * icc2**2 * fj**2 + (n * (1 + (k - 1) * icc2) - k * icc2) ** 2
v = vn / vd
f2u = f.ppf(1 - alpha / 2, n - 1, v)
Expand Down
1 change: 0 additions & 1 deletion pingouin/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

18 changes: 9 additions & 9 deletions pingouin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def _postprocess_dataframe(df):

def _get_round_setting_for(row, col):
keys_to_check = (
"round.cell.[{}]x[{}]".format(row, col),
"round.column.{}".format(col),
"round.row.{}".format(row),
f"round.cell.[{row}]x[{col}]",
f"round.column.{col}",
f"round.row.{row}",
)
for key in keys_to_check:
try:
Expand Down Expand Up @@ -397,11 +397,11 @@ def _is_statsmodels_installed(raise_error=False):
import statsmodels # noqa

is_installed = True
except IOError: # pragma: no cover
except OSError: # pragma: no cover
is_installed = False
# Raise error (if needed) :
if raise_error and not is_installed: # pragma: no cover
raise IOError("statsmodels needs to be installed. Please use `pip " "install statsmodels`.")
raise OSError("statsmodels needs to be installed. Please use `pip " "install statsmodels`.")
return is_installed


Expand All @@ -411,11 +411,11 @@ def _is_sklearn_installed(raise_error=False):
import sklearn # noqa

is_installed = True
except IOError: # pragma: no cover
except OSError: # pragma: no cover
is_installed = False
# Raise error (if needed) :
if raise_error and not is_installed: # pragma: no cover
raise IOError("sklearn needs to be installed. Please use `pip " "install scikit-learn`.")
raise OSError("sklearn needs to be installed. Please use `pip " "install scikit-learn`.")
return is_installed


Expand All @@ -425,9 +425,9 @@ def _is_mpmath_installed(raise_error=False):
import mpmath # noqa

is_installed = True
except IOError: # pragma: no cover
except OSError: # pragma: no cover
is_installed = False
# Raise error (if needed) :
if raise_error and not is_installed: # pragma: no cover
raise IOError("mpmath needs to be installed. Please use `pip " "install mpmath`.")
raise OSError("mpmath needs to be installed. Please use `pip " "install mpmath`.")
return is_installed

0 comments on commit faad22a

Please sign in to comment.