Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra check if both values are NA in bulk_upsert #53

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ jobs:
strategy:
matrix:
python-version:
- "3.10" # Earliest version supported by ixmp4
- "3.11"
- "3.12" # Latest version supported by ixmp4

- "3.10" # Earliest version supported by ixmp4
- "3.11"
- "3.12" # Latest version supported by ixmp4
with-pyarrow:
- false
include:
- python-version: "3.12"
with-pyarrow: true
runs-on: ubuntu-latest
services:
postgres:
Expand Down Expand Up @@ -65,6 +69,10 @@ jobs:
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install PyArrow
if: ${{ matrix.with-pyarrow }}
run: pip install pyarrow

- name: Install library
run: poetry install --no-interaction
#----------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion ixmp4/data/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,14 @@ def bulk_upsert_chunk(self, df: pd.DataFrame) -> None:
for col in self.model_class.updateable_columns:
updated_col = col + self.merge_suffix
if updated_col in df.columns:
cond.append(df[col] != df[updated_col])
# coerce to same type so the inequality
# operation works with pyarrow installed
df[updated_col] = df[updated_col].astype(df[col].dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a line explaining why this is necessary? And a test (in a GitHub Action that explicitly installs pyarrow) to guard against regression?

are_not_equal = df[col] != df[updated_col]
# extra check if both values are NA because NA == NA = NA
# in pandas with pyarrow
both_are_na = pd.isna(df[col]) & pd.isna(df[updated_col])
cond.append(~both_are_na | are_not_equal)

df["differs"] = np.where(np.logical_or.reduce(cond), True, False)

Expand Down
Loading
Loading