Skip to content

feat(downsample_cells_template): add downsample_cells_template functi…#393

Merged
fangliu117 merged 1 commit intodevfrom
template_downsample_cells
Aug 4, 2025
Merged

feat(downsample_cells_template): add downsample_cells_template functi…#393
fangliu117 merged 1 commit intodevfrom
template_downsample_cells

Conversation

@fangliu117
Copy link
Collaborator

…on and unit tests

Copilot AI review requested due to automatic review settings August 4, 2025 13:07
Copy link
Contributor

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 a new downsample_cells_template function that provides a platform-agnostic interface for cell downsampling operations, converted from NIDAP template functionality. The implementation includes comprehensive parameter handling, multiple input format support, and flexible output options.

  • Implements run_from_json function with support for JSON, dict, and direct DataFrame inputs
  • Adds comprehensive test coverage including I/O workflows, error validation, and function mocking
  • Provides CLI interface and handles multiple file formats (CSV, pickle)

Reviewed Changes

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

File Description
src/spac/templates/downsample_cells_template.py Main template implementation with parameter parsing, data loading, and downsample execution
tests/templates/test_downsample_cells_template.py Comprehensive unit tests covering various input formats, error cases, and function validation

import pickle

# Add parent directory to path for imports
sys.path.append(str(Path(__file__).parent.parent.parent))
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

Modifying sys.path at runtime is an anti-pattern that can cause import issues. Consider using relative imports or proper package structure instead.

Suggested change
sys.path.append(str(Path(__file__).parent.parent.parent))

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +19
sys.path.append(
os.path.dirname(os.path.realpath(__file__)) + "/../../src"
)
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

Modifying sys.path in tests is an anti-pattern. Consider using proper test discovery mechanisms or PYTHONPATH configuration instead.

Suggested change
sys.path.append(
os.path.dirname(os.path.realpath(__file__)) + "/../../src"
)

Copilot uses AI. Check for mistakes.
Comment on lines +100 to +101
print("Downsampled! Processed dataset info:")
print(down_sampled_dataset.info())
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

[nitpick] Using print statements in library code reduces flexibility for users who may want to control logging. Consider using the logging module instead.

Suggested change
print("Downsampled! Processed dataset info:")
print(down_sampled_dataset.info())
logging.info("Downsampled! Processed dataset info:")
logging.info(down_sampled_dataset.info())

Copilot uses AI. Check for mistakes.
Comment on lines +113 to +124
print(
f"Downsample Cells completed → {saved_files[output_file]}"
)
return saved_files
else:
# Return the dataframe directly for in-memory workflows
print("Returning DataFrame (not saving to file)")
return down_sampled_dataset


# CLI interface
if __name__ == "__main__":
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

[nitpick] Using print statements in library code reduces flexibility for users who may want to control logging. Consider using the logging module instead.

Suggested change
print(
f"Downsample Cells completed → {saved_files[output_file]}"
)
return saved_files
else:
# Return the dataframe directly for in-memory workflows
print("Returning DataFrame (not saving to file)")
return down_sampled_dataset
# CLI interface
if __name__ == "__main__":
logging.info(
f"Downsample Cells completed → {saved_files[output_file]}"
)
return saved_files
else:
# Return the dataframe directly for in-memory workflows
logging.info("Returning DataFrame (not saving to file)")
return down_sampled_dataset
# CLI interface
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)

Copilot uses AI. Check for mistakes.
return saved_files
else:
# Return the dataframe directly for in-memory workflows
print("Returning DataFrame (not saving to file)")
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

[nitpick] Using print statements in library code reduces flexibility for users who may want to control logging. Consider using the logging module instead.

Copilot uses AI. Check for mistakes.
@fangliu117 fangliu117 merged commit 71dc3d6 into dev Aug 4, 2025
19 checks passed
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