From fc2c5b025adb4ab8f4c6ddb41ad282231965833d Mon Sep 17 00:00:00 2001 From: victorventuri Date: Tue, 19 Aug 2025 14:44:59 -0500 Subject: [PATCH 1/4] Avoiding warnings The way pandas deals with the addition of new columns is a bit weird, as there is a difference between a view of a dataframe, a copy of it, and the dataframe itself. By using `.loc` with a specified tuple of new columns to add, we do what pandas deems correct, and circumvent several annoying warnings --- battdat/postprocess/tagging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/battdat/postprocess/tagging.py b/battdat/postprocess/tagging.py index 5da1302..62ed8f8 100644 --- a/battdat/postprocess/tagging.py +++ b/battdat/postprocess/tagging.py @@ -37,7 +37,7 @@ def column_names(self) -> List[str]: def enhance(self, df: pd.DataFrame): # Insert a new column into the dataframe, starting with everything marked as other - df['method'] = ControlMethod.other + df.loc[:, ('method',)] = ControlMethod.other # array of indexes cycles = df.groupby(["cycle_number", "step_index"]) @@ -148,7 +148,7 @@ def column_names(self) -> List[str]: def enhance(self, data: pd.DataFrame) -> None: logger.debug('Adding states') - data['state'] = data.apply(_determine_state, axis=1, args=(self.rest_curr_threshold,)) + data.loc[:, ('state',)] = data.apply(_determine_state, axis=1, args=(self.rest_curr_threshold,)) class AddSteps(RawDataEnhancer): @@ -192,7 +192,7 @@ def _determine_steps(df: DataFrame, column: str, output_col: str): # The step number is equal to the number of changes observed previously in a batch # Step 1: Compute the changes since the beginning of file - df[output_col] = change.cumsum() + df.loc[:, (output_col,)] = change.cumsum() # Step 2: Adjust so that each cycle starts with step 0 for _, cycle in df.groupby("cycle_number"): From ae433953cb2d6790bd5f5c7b904e9f7b32c9e6ba Mon Sep 17 00:00:00 2001 From: victorventuri Date: Tue, 19 Aug 2025 14:47:50 -0500 Subject: [PATCH 2/4] Changing the name of the CE column The CE-adjusted charge column has a new, more descriptive name. --- battdat/postprocess/integral.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/battdat/postprocess/integral.py b/battdat/postprocess/integral.py index 00df112..2600b01 100644 --- a/battdat/postprocess/integral.py +++ b/battdat/postprocess/integral.py @@ -135,8 +135,8 @@ class StateOfCharge(RawDataEnhancer): Output dataframe has 3 new columns: - ``cycled_charge``: Amount of observed charge cycled since the beginning of the cycle, in A-hr - ``cycled_energy``: Amount of observed energy cycled since the beginning of the cycle, in W-hr - - ``CE_charge``: Amount of charge in the battery relative to the beginning of the cycle, accounting for Coulombic - Efficiency, in A-hr + - ``CE_adjusted_charge``: Amount of charge in the battery relative to the beginning of the cycle, accounting for + Coulombic Efficiency (CE), in A-hr """ def __init__(self, coulombic_efficiency: float = 1.0): """ @@ -157,7 +157,7 @@ def coulombic_efficiency(self, value: float): @property def column_names(self) -> List[str]: - return ['cycled_charge', 'cycled_energy', 'CE_charge'] + return ['cycled_charge', 'cycled_energy', 'CE_adjusted_charge'] def _get_CE_adjusted_curr(self, current: np.ndarray) -> np.ndarray: """Adjust the current based on the coulombic efficiency @@ -168,14 +168,13 @@ def _get_CE_adjusted_curr(self, current: np.ndarray) -> np.ndarray: Returns: Adjusted current array in A """ - adjusted_current = current.copy() - adjusted_current[current > 0] *= self.coulombic_efficiency - return adjusted_current + adjusted_current = np.where(current > 0, self.coulombic_efficiency * current, current) + return adjusted_current.flatten() def enhance(self, data: pd.DataFrame): # Add columns for the capacity and energy for c in self.column_names: - data[c] = np.nan + data.loc[:, (c,)] = np.nan # Compute the capacity and energy for each cycle ordered_copy = data.reset_index() # Ensure a sequential ordering from 0 @@ -193,5 +192,5 @@ def enhance(self, data: pd.DataFrame): # Store them in the raw data data.loc[cycle_subset['index'], 'cycled_charge'] = capacity_change / 3600 # To A-hr - data.loc[cycle_subset['index'], 'CE_charge'] = ce_charge / 3600 # To A-hr + data.loc[cycle_subset['index'], 'CE_adjusted_charge'] = ce_charge / 3600 # To A-hr data.loc[cycle_subset['index'], 'cycled_energy'] = energy_change / 3600 # To W-hr From 81bba54dd3151ea708620254f9c47369c2b385ce Mon Sep 17 00:00:00 2001 From: victorventuri Date: Tue, 19 Aug 2025 15:11:35 -0500 Subject: [PATCH 3/4] trying to avoid the nuisance of Coverall 422 --- .github/workflows/python-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a163124..fbf55d1 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -27,9 +27,9 @@ jobs: - name: Coveralls run: | pip install coveralls - coveralls --service=github + coveralls --service=github-actions env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} - name: Test example notebooks if: ${{ runner.os == 'Linux' }} run: | From f9df7deca2080f8b5261a268172aeb593a98a043 Mon Sep 17 00:00:00 2001 From: victorventuri Date: Tue, 19 Aug 2025 15:14:07 -0500 Subject: [PATCH 4/4] trying again to deal with coveralls --- .github/workflows/python-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index fbf55d1..d2adb5f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -29,6 +29,7 @@ jobs: pip install coveralls coveralls --service=github-actions env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} - name: Test example notebooks if: ${{ runner.os == 'Linux' }}