-
Notifications
You must be signed in to change notification settings - Fork 38
fix: time_to_seconds to include day format D-HH:MM:SS #360
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
base: main
Are you sure you want to change the base?
Conversation
… Cheshakoneko 60975461+Cheshakoneko@users.noreply.github.com
WalkthroughEnhanced time_to_seconds in efficiency_report.py to robustly parse SLURM time formats (D-HH:MM:SS, HH:MM:SS, MM:SS, S), handle optional days, trim/normalize inputs, treat empty/NA as 0, and return consistent numeric types. Updated docstring and improved input preprocessing and string handling. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
snakemake_executor_plugin_slurm/efficiency_report.py (2)
13-16
: Consider optimizing duplicate string conversion.Lines 13 and 16 both call
str(time_str).strip()
, which is redundant. Consider restructuring for clarity and efficiency:- if pd.isna(time_str) or str(time_str).strip() == "": + if pd.isna(time_str): return 0 - - time_str = str(time_str).strip() + time_str = str(time_str).strip() + if time_str == "": + return 0
18-21
: Consider defensive handling for malformed day format.If the input contains a hyphen but has an empty day or time component (e.g.,
"-"
,"5-"
, or"-12:34"
), the function will raise aValueError
. While SLURM should only return valid formats, adding validation would make the function more robust.days = 0 if "-" in time_str: # Format D-HH:MM:SS d, time_str = time_str.split("-", 1) + if not d or not time_str: + return 0 days = int(d) * 86400
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
snakemake_executor_plugin_slurm/efficiency_report.py
(1 hunks)
🔇 Additional comments (2)
snakemake_executor_plugin_slurm/efficiency_report.py (2)
24-34
: LGTM! Good enhancement for handling days and fractional seconds.The logic correctly:
- Adds the
days
offset in all three time format branches- Uses
float()
for seconds to handle fractional values (e.g., from SLURM's microsecond precision)- Maintains the existing fallback to
0
for unrecognized formats
11-34
: Add comprehensive tests for SLURM time parsing
Include cases for:
- D-HH:MM:SS formats (e.g. “1-12:34:56”, “0-00:05:30”)
- HH:MM:SS (“12:34:56”)
- MM:SS (“34:56”)
- S (“56”)
- Fractional seconds (“2-00:00:30.5”)
- Edge cases: empty/None, zero values, large day counts
import shlex | ||
|
||
import os # only temporarily needed for printf debugging | ||
import os # only temporarily needed for print debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify or remove the temporary import.
The import os
is marked as "only temporarily needed for print debugging" but is actively used on line 228. Either remove the import and the os.listdir()
call if they're truly temporary, or remove the misleading comment.
🤖 Prompt for AI Agents
In snakemake_executor_plugin_slurm/efficiency_report.py around line 7 (and usage
at line 228), the import os is marked as "only temporarily needed for print
debugging" but is actually used via os.listdir() on line 228; either remove the
import and the os.listdir() call (and any debug prints relying on it) if they
were temporary, or remove/adjust the misleading comment and keep the import and
call if they are required for functionality; update or remove related debug
prints and ensure imports and code reflect the chosen approach so linter/tests
don't complain.
@Cheshakoneko thank you for this PR immediately fixing, what I - apparently - overlooked! |
I really like your PR - it just turned out, that test cases were missing, and we also need to add checks for fractional seconds (which I think we can totally discard, but the HPC world is crazy about precision, so ...) Well, I cloned your PR, but I cannot push to your fork, so #362 might replace your PR - but you are still a contributor. And a jolly good one, I might say! |
This PR extends the
time_to_seconds
function to correctly parse theD-HH:MM:SS
time format, which SLURM can also return. The function splits the time string if a hyphen-
is present and multiplies the number of days by 86400 seconds.Summary by CodeRabbit
New Features
Bug Fixes