Support passing np.timedelta64 to parameters that expect a sequence (e.g., 'region')#4358
Support passing np.timedelta64 to parameters that expect a sequence (e.g., 'region')#4358
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for passing np.timedelta64 objects to parameters that expect a sequence, such as the region parameter in GMT plotting functions. The implementation converts timedelta64 objects to their numeric values in their original units when joining sequences into strings.
Changes:
- Modified
sequence_joinfunction inpygmt/helpers/utils.pyto handlenp.timedelta64objects by extracting their numeric values - Updated
test_plot_timedelta64test to use timedelta64 objects in theregionparameter, testing the new functionality - Added comprehensive docstring examples showing timedelta64 handling with various time units
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pygmt/helpers/utils.py | Added timedelta64 handling logic to convert timedelta64 objects to numeric strings, and updated docstring with examples |
| pygmt/tests/test_plot.py | Refactored test to use timedelta64 objects in the region parameter, testing the new functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2fca0be to
e222f52
Compare
pygmt/helpers/utils.py
Outdated
| if unit == "generic": | ||
| _values.append(str(int(item))) | ||
| else: | ||
| _values.append(str(item.astype(f"timedelta64[{unit}]").astype(int))) |
There was a problem hiding this comment.
Why is item converted into a timedelta64 value again here?
There was a problem hiding this comment.
You're right, conversion is not necessary. Simplified in 92280b9.
Related to #2848.