From c4da052acbd37e73566dc337af15c29f7c4a4e13 Mon Sep 17 00:00:00 2001 From: Morgan Williams Date: Fri, 17 May 2024 11:30:16 +1000 Subject: [PATCH] Formatting - comp.codata --- pyrolite/comp/codata.py | 42 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/pyrolite/comp/codata.py b/pyrolite/comp/codata.py index 7ce4c346..e3c87a0c 100644 --- a/pyrolite/comp/codata.py +++ b/pyrolite/comp/codata.py @@ -1,4 +1,5 @@ import warnings + import numpy as np import pandas as pd import scipy.special @@ -39,7 +40,10 @@ def close(X: np.ndarray, sumf=np.sum): """ if np.any(X <= 0): - warnings.warn("Non-positive entries found. Closure operation assumes all positive entries.", UserWarning) + warnings.warn( + "Non-positive entries found. Closure operation assumes all positive entries.", + UserWarning, + ) if X.ndim == 2: C = np.array(sumf(X, axis=1), dtype=float)[:, np.newaxis] @@ -81,16 +85,20 @@ def renormalise(df: pd.DataFrame, components: list = [], scale=100.0): dfc = dfc[components] if (dfc <= 0).any().any(): - warnings.warn("Non-positive entries found in specified components. " - "Negative values have been replaced with NaN. " - "Renormalisation assumes all positive entries.", UserWarning) + warnings.warn( + "Non-positive entries found in specified components. " + "Negative values have been replaced with NaN. " + "Renormalisation assumes all positive entries.", + UserWarning, + ) # Replace negative values with NaN dfc[dfc < 0] = np.nan # Renormalise all columns if no components are specified sum_rows = dfc.sum(axis=1) - sum_rows.replace(0, np.nan, inplace=True) # Handle division by zero by replacing zeros with NaN + # Handle division by zero by replacing zeros with NaN + sum_rows.replace(0, np.nan, inplace=True) dfc = dfc.divide(sum_rows, axis=0) * scale return dfc @@ -347,9 +355,11 @@ def get_ALR_labels(df, mode="simple", ind=-1, **kwargs): names = [ r"{} / {}".format( - c - if c not in __sympy_protected_variables__ - else __sympy_protected_variables__[c], + ( + c + if c not in __sympy_protected_variables__ + else __sympy_protected_variables__[c] + ), df.columns[ind], ) for c in df.columns @@ -399,9 +409,11 @@ def get_CLR_labels(df, mode="simple", **kwargs): names = [ r"{} / γ".format( - c - if c not in __sympy_protected_variables__ - else __sympy_protected_variables__[c], + ( + c + if c not in __sympy_protected_variables__ + else __sympy_protected_variables__[c] + ), ) for c in df.columns ] @@ -462,9 +474,11 @@ def get_ILR_labels(df, mode="latex", **kwargs): # sub in Phi (the CLR normalisation variable) names = [ r"{} / γ".format( - c - if c not in __sympy_protected_variables__ - else __sympy_protected_variables__[c], + ( + c + if c not in __sympy_protected_variables__ + else __sympy_protected_variables__[c] + ), ) for c in df.columns ]