Skip to content

Support passing np.timedelta64 to parameters that expect a sequence (e.g., 'region')#4358

Merged
weiji14 merged 6 commits intomainfrom
timedelta64/support
Jan 22, 2026
Merged

Support passing np.timedelta64 to parameters that expect a sequence (e.g., 'region')#4358
weiji14 merged 6 commits intomainfrom
timedelta64/support

Conversation

@seisman
Copy link
Member

@seisman seisman commented Jan 17, 2026

Related to #2848.

import pygmt
import numpy as np

fig = pygmt.Figure()
fig.basemap(
    projection="X8c/5c",
    region=[np.timedelta64(0, "D"), np.timedelta64(8, "D"), 0, 10],
    frame=["WSne", "xaf+lForecast Days", "yaf+lRMSE"],
)
fig.plot(
    x=np.arange(np.timedelta64(0, "D"), np.timedelta64(8, "D")),
    y=np.geomspace(start=0.1, stop=9, num=8),
    style="c0.2c",
    pen="1p",
)
fig.show()
timedelta64

@seisman seisman added this to the 0.19.0 milestone Jan 17, 2026
@seisman seisman added enhancement Improving an existing feature needs review This PR has higher priority and needs review. run/benchmark Trigger the benchmark workflow in PRs labels Jan 17, 2026
@seisman seisman requested review from Copilot and weiji14 January 17, 2026 13:52
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 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_join function in pygmt/helpers/utils.py to handle np.timedelta64 objects by extracting their numeric values
  • Updated test_plot_timedelta64 test to use timedelta64 objects in the region parameter, 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-hq
Copy link

codspeed-hq bot commented Jan 17, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing timedelta64/support (92280b9) with main (3175d52)

Summary

✅ 104 untouched benchmarks

@seisman seisman force-pushed the timedelta64/support branch from 2fca0be to e222f52 Compare January 17, 2026 14:42
if unit == "generic":
_values.append(str(int(item)))
else:
_values.append(str(item.astype(f"timedelta64[{unit}]").astype(int)))
Copy link
Member

Choose a reason for hiding this comment

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

Why is item converted into a timedelta64 value again here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, conversion is not necessary. Simplified in 92280b9.

@weiji14 weiji14 merged commit 653f6e1 into main Jan 22, 2026
23 of 24 checks passed
@weiji14 weiji14 deleted the timedelta64/support branch January 22, 2026 19:35
@weiji14 weiji14 removed needs review This PR has higher priority and needs review. run/benchmark Trigger the benchmark workflow in PRs labels Jan 22, 2026
@seisman seisman mentioned this pull request Jan 24, 2026
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants