Skip to content

Add parameter validation to roundDatetimeToInterval#34

Merged
SBFRF merged 2 commits into
refactor/phase1-foundationfrom
copilot/sub-pr-26
Feb 2, 2026
Merged

Add parameter validation to roundDatetimeToInterval#34
SBFRF merged 2 commits into
refactor/phase1-foundationfrom
copilot/sub-pr-26

Conversation

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

The roundDatetimeToInterval function accepted invalid method parameter values and silently defaulted to 'nearest' behavior without warning users.

Changes

  • Parameter validation: Added explicit validation that method is one of ['nearest', 'floor', 'ceil'], raising InvalidParameterError with parameter details for invalid values
  • Test coverage: Added 9 test cases covering valid methods, invalid inputs, and edge cases
  • Bug fix: Corrected indentation error in getOutsideData.py that caused syntax error during import

Example

from murgtools.utils.sblib import roundDatetimeToInterval
import datetime as DT

dt = DT.datetime(2024, 6, 15, 14, 23, 45)

# Valid usage
roundDatetimeToInterval(dt, 30, method='floor')  # Works as expected

# Invalid usage now raises clear error
roundDatetimeToInterval(dt, 30, method='round')
# InvalidParameterError: Invalid rounding method: 'round'
# Expected: One of ['nearest', 'floor', 'ceil']

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: SBFRF <8375832+SBFRF@users.noreply.github.com>

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • chldata.erdc.dren.mil
    • Triggering command: /usr/bin/python python -m pytest tests/test_sblib.py tests/test_config.py -v (dns block)
  • coastalimaging.erdc.dren.mil
    • Triggering command: /usr/bin/python python -m pytest tests/test_sblib.py tests/test_config.py -v (dns block)
  • earth-search.aws.element84.com
    • Triggering command: /usr/bin/python python -m pytest tests/test_sblib.py tests/test_config.py -v (dns block)
  • nomads.ncep.noaa.gov
    • Triggering command: /usr/bin/python python -m pytest tests/test_sblib.py tests/test_config.py -v (dns block)
  • planetarycomputer.microsoft.com
    • Triggering command: /usr/bin/python python -m pytest tests/test_sblib.py tests/test_config.py -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] WIP Address feedback on Centralized Config, Exceptions, and Tests PR Add parameter validation to roundDatetimeToInterval Feb 2, 2026
Copilot AI requested a review from SBFRF February 2, 2026 01:57
@SBFRF
SBFRF marked this pull request as ready for review February 2, 2026 01:58
Copilot AI review requested due to automatic review settings February 2, 2026 01:58
@SBFRF
SBFRF merged commit 3cceb43 into refactor/phase1-foundation Feb 2, 2026
4 checks passed
@SBFRF
SBFRF deleted the copilot/sub-pr-26 branch February 2, 2026 01:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 parameter validation to the roundDatetimeToInterval function to prevent silent failures when invalid rounding methods are passed. Previously, invalid method values would default to 'nearest' behavior without warning users.

Changes:

  • Added explicit validation for the method parameter, raising InvalidParameterError for values other than 'nearest', 'floor', or 'ceil'
  • Created comprehensive test suite with 9 test cases covering valid methods, invalid inputs, and edge cases like midnight overflow
  • Fixed indentation in getOutsideData.py to properly nest try-except blocks for GeoTIFF tag extraction

Reviewed changes

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

File Description
tests/test_sblib.py New test file with comprehensive coverage for roundDatetimeToInterval function, testing all valid methods and multiple invalid input scenarios
murgtools/utils/sblib.py Added parameter validation logic, InvalidParameterError import, and updated docstring to document the new exception
murgtools/getdata/getOutsideData.py Fixed indentation by wrapping GeoTIFF tag extraction code in try-except block for proper error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants