Skip to content

Provide an option to handle NaN for pyarchappl-get#20

Merged
zhangt58 merged 9 commits intomasterfrom
cli
Sep 19, 2025
Merged

Provide an option to handle NaN for pyarchappl-get#20
zhangt58 merged 9 commits intomasterfrom
cli

Conversation

@zhangt58
Copy link
Owner

No description provided.

@zhangt58 zhangt58 requested a review from Copilot September 19, 2025 15:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to handle NaN (Not a Number) values in the data retrieval process by providing configurable fill methods. Previously, the code was hardcoded to use forward fill ('ffill') for handling missing data.

  • Adds a new --fillna-method command line argument with multiple options for handling NaN values
  • Implements support for interpolation methods ('nearest', 'linear') that require scipy as an optional dependency
  • Updates the data processing logic to conditionally apply different fill strategies based on user preference

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
main/scripts/get.py Adds command line argument for fillna method and passes it to data processing function
main/contrib/data.py Implements the core NaN handling logic with multiple fill methods and scipy dependency checking
main/init.py Adds scipy installation detection similar to existing tqdm detection pattern

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

help="Print the site configuration with essential dependencies and their versions.")
parser.add_argument('--fillna-method', dest='fillna_method', default='ffill',
help="The method defines how the invalid data (NaN) should be filled, "
"defaults 'ffill', the last valid one is used, other options: "
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

There's a grammatical error in the help text. 'defaults 'ffill'' should be 'defaults to 'ffill''.

Suggested change
"defaults 'ffill', the last valid one is used, other options: "
"defaults to 'ffill', the last valid one is used, other options: "

Copilot uses AI. Check for mistakes.
if fillna_method in ("nearest", "linear"):
data.interpolate(method=fillna_method, inplace=True)
if fillna_method == "ffill":
data = data.bfill()
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

There's a logic error: both 'ffill' and 'bfill' methods call data.bfill(). The 'ffill' case should call data.ffill() instead.

Suggested change
data = data.bfill()
data = data.ffill()

Copilot uses AI. Check for mistakes.
Comment on lines 155 to 163
if fillna_method == "nearest" and not SCIPY_INSTALLED:
_LOGGER.warning("Install scipy to support fillna_method 'nearest', fallback to 'ffill'.")
fillna_method = "ffill"
if fillna_method in ("nearest", "linear"):
data.interpolate(method=fillna_method, inplace=True)
if fillna_method == "ffill":
data = data.bfill()
if fillna_method == "bfill":
data = data.bfill()
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

The 'none' option mentioned in the help text is not handled in the implementation. Consider adding an explicit check for 'none' to make the code more maintainable and clear about when no filling should occur.

Suggested change
if fillna_method == "nearest" and not SCIPY_INSTALLED:
_LOGGER.warning("Install scipy to support fillna_method 'nearest', fallback to 'ffill'.")
fillna_method = "ffill"
if fillna_method in ("nearest", "linear"):
data.interpolate(method=fillna_method, inplace=True)
if fillna_method == "ffill":
data = data.bfill()
if fillna_method == "bfill":
data = data.bfill()
if fillna_method == "none":
_LOGGER.info("No filling of missing data will be performed (fillna_method='none').")
else:
if fillna_method == "nearest" and not SCIPY_INSTALLED:
_LOGGER.warning("Install scipy to support fillna_method 'nearest', fallback to 'ffill'.")
fillna_method = "ffill"
if fillna_method in ("nearest", "linear"):
data.interpolate(method=fillna_method, inplace=True)
if fillna_method == "ffill":
data = data.bfill()
if fillna_method == "bfill":
data = data.bfill()

Copilot uses AI. Check for mistakes.
@zhangt58 zhangt58 changed the title Provde an option to handle NaN Provide an option to handle NaN Sep 19, 2025
@zhangt58 zhangt58 changed the title Provide an option to handle NaN Provide an option to handle NaN for pyarchappl-get Sep 19, 2025
@zhangt58 zhangt58 merged commit 7ec4c1f into master Sep 19, 2025
7 checks passed
@zhangt58 zhangt58 deleted the cli branch September 19, 2025 15:34
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.

1 participant