Skip to content

Conversation

@d-chambers
Copy link
Contributor

@d-chambers d-chambers commented Sep 15, 2025

Description

This PR makes drop_na include inf by default but this can be controlled with a new include_inf argument. Same for fill_na.

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes.
  • documented the new feature with docstrings or appropriate doc page.
  • included a test. See testing guidelines.
  • your name has been added to the contributors page (docs/contributors.md).
  • added the "ready_for_review" tag once the PR is ready to be reviewed.

Summary by CodeRabbit

  • New Features

    • Added include_inf option to treat non-finite values (Inf, -Inf) as missing for drop/fill operations.
  • Behavior Change

    • dropna/fillna now treat non-finite values as missing by default; set include_inf=False to preserve prior NaN-only behavior.
  • Tests

    • Expanded tests and shared fixtures to validate NaN/Inf handling for drop and fill scenarios.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Walkthrough

Adds an include_inf parameter (default True) to dropna and fillna in dascore/proc/basic.py so non-finite values (Inf/-Inf) are treated as nullish when enabled. Updates null/replacement masks accordingly. Tests refactored to module-level fixtures and add tests for Inf handling in dropna and fillna.

Changes

Cohort / File(s) Summary
Processing functions update
dascore/proc/basic.py
Added include_inf parameter (default True) to dropna and fillna. When include_inf=True masks use ~np.isfinite(patch.data); when False use pd.isnull(...). Updated signatures and docstrings; default behavior now treats Inf/-Inf as nullish.
Tests: fixtures and Inf handling
tests/test_proc/test_basic.py
Moved fixtures to module level and added patch_with_null, patch_with_inf, and patch_3d_with_null. Removed duplicate class-scoped fixtures. Added tests test_inf_dropped, test_inf_not_dropped, test_fill_inf, and test_fill_no_inf to verify include_inf=True/False behavior.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "np.dropna to include inf" is concise and captures the primary intent of the changeset—treating infinite values as missing for dropna—and it aligns with the change that adds an include_inf parameter. It is short and will be clear to many reviewers. However, the "np." prefix can mislead readers into thinking this modifies NumPy itself rather than this project's dropna implementation, and the title omits the parallel fillna change.
Description Check ✅ Passed The PR description provides a concise Description that correctly states the change (drop_na and fill_na now treat inf as missing and gain an include_inf argument) and includes the repository checklist, so the intent is clear. The description is minimal and omits a link to any related issue, does not explicitly state that docstrings/docs were updated, and the checklist items are left unchecked. The raw changes do include test updates that exercise NaN/Inf behavior, but the description does not call those tests out. Overall the description communicates the intent but is incomplete relative to the template's expectations for documentation, references, and checklist completion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch drop_na_inf

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7aee9d5 and 79c880b.

📒 Files selected for processing (1)
  • dascore/proc/basic.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dascore/proc/basic.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.12)
  • GitHub Check: test_code_min_deps (windows-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.11)
  • GitHub Check: test_code (windows-latest, 3.13)
  • GitHub Check: test_code (macos-latest, 3.12)
  • GitHub Check: test_code_min_deps (macos-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.12)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.13)
  • GitHub Check: test_code_min_deps (windows-latest, 3.13)
  • GitHub Check: test_code (ubuntu-latest, 3.13)
  • GitHub Check: test_code_min_deps (macos-latest, 3.13)
  • GitHub Check: test_code (macos-latest, 3.13)
  • GitHub Check: test_code (windows-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.11)
  • GitHub Check: test_code (ubuntu-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.12)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (4242dc7) to head (79c880b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #535   +/-   ##
=======================================
  Coverage   99.88%   99.88%           
=======================================
  Files         122      122           
  Lines       10040    10044    +4     
=======================================
+ Hits        10028    10032    +4     
  Misses         12       12           
Flag Coverage Δ
unittests 99.88% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
dascore/proc/basic.py (2)

511-512: Update the docstring to align with the new behavior.

The docstring states that "nullish" is defined by pandas.isnull, but with include_inf=True (the default), the function now uses np.isfinite which has different behavior. The docstring should clarify this distinction.

Apply this diff to update the docstring:

    Notes
    -----
-    "nullish" is defined by `pandas.isnull`.
+    When include_inf is False, "nullish" is defined by `pandas.isnull`.
+    When include_inf is True (default), "nullish" includes non-finite values
+    (NaN, inf, -inf) as determined by `numpy.isfinite`.

561-562: Update the docstring to align with the new behavior.

Similar to dropna, the docstring should clarify the distinction between the behavior when include_inf is True vs False.

Apply this diff to update the docstring:

    Notes
    -----
-    "nullish" is defined by `pandas.isnull`.
+    When include_inf is False, "nullish" is defined by `pandas.isnull`.
+    When include_inf is True (default), "nullish" includes non-finite values
+    (NaN, inf, -inf) as determined by `numpy.isfinite`.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4242dc7 and c130c26.

📒 Files selected for processing (2)
  • dascore/proc/basic.py (6 hunks)
  • tests/test_proc/test_basic.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
dascore/proc/basic.py (2)
dascore/core/patch.py (1)
  • data (213-215)
dascore/core/coords.py (1)
  • data (606-608)
tests/test_proc/test_basic.py (3)
dascore/examples.py (3)
  • patch_with_null (115-130)
  • get_example_patch (635-682)
  • random_patch (29-111)
tests/conftest.py (3)
  • random_patch (282-284)
  • range_patch_3d (355-364)
  • patch (375-377)
dascore/proc/basic.py (3)
  • update (159-199)
  • dropna (493-547)
  • fillna (551-585)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: test_code (windows-latest, 3.11)
  • GitHub Check: test_code (windows-latest, 3.12)
  • GitHub Check: test_code (ubuntu-latest, 3.10)
  • GitHub Check: test_code (windows-latest, 3.13)
  • GitHub Check: test_code (macos-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.13)
  • GitHub Check: test_code (windows-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.13)
  • GitHub Check: test_code (ubuntu-latest, 3.12)
  • GitHub Check: test_code_min_deps (windows-latest, 3.12)
  • GitHub Check: test_code_min_deps (windows-latest, 3.13)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.12)
  • GitHub Check: test_code_min_deps (macos-latest, 3.12)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.13)
  • GitHub Check: test_code_min_deps (macos-latest, 3.13)
🔇 Additional comments (10)
dascore/proc/basic.py (4)

493-498: LGTM! Well-designed parameter signature.

The addition of the include_inf parameter with a default value of True provides a clear and intuitive API for controlling whether infinite values should be treated as nullish values in the dropna operation.


530-533: LGTM! Clear conditional logic for handling finite vs null values.

The implementation correctly uses np.isfinite when include_inf=True to catch NaN, inf, and -inf values, and falls back to pd.isnull when include_inf=False for traditional null-only behavior.


551-551: LGTM! Consistent parameter signature with dropna.

The include_inf parameter maintains consistency with the dropna function signature.


578-581: LGTM! Consistent implementation with dropna logic.

The conditional logic correctly mirrors the approach used in dropna, using np.isfinite for comprehensive non-finite value detection and pd.isnull for traditional null-only behavior.

tests/test_proc/test_basic.py (6)

33-36: LGTM! Good use of session-scoped fixture.

Using session scope for the patch_with_null fixture is efficient since this test data doesn't change and can be shared across all tests.


39-45: LGTM! Well-designed fixture for testing infinite values.

The fixture creates a patch with infinite values by setting column 2 to np.inf, providing good test coverage for the new include_inf functionality.


48-56: LGTM! Appropriate use of class-scoped fixture.

The class scope is appropriate for patch_3d_with_null since it's specific to certain test classes and creates a more complex 3D test structure.


496-499: LGTM! Good test coverage for the new include_inf=True behavior.

The test verifies that when include_inf=True (the default), infinite values are properly dropped from the data.


501-504: LGTM! Good test coverage for include_inf=False behavior.

The test ensures backward compatibility by verifying that when include_inf=False, infinite values are preserved in the data.


530-534: LGTM! Good test coverage for fillna with infinite values.

The test verifies that fillna with include_inf=True correctly fills infinite values by checking that the count of zeros increases after the operation.

@d-chambers d-chambers merged commit 13b2bf2 into master Sep 15, 2025
22 checks passed
@d-chambers d-chambers deleted the drop_na_inf branch September 19, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants