Skip to content

question about datetime_unit of xarray.DataArray.differentiate #8000

Answered by spencerkclark
jesieleo asked this question in Q&A
Discussion options

You must be logged in to vote

That's correct. The documentation is unfortunately misleading (#8006; thank you for bringing this to our attention!) and these options do not apply, in part for the reason you stated.

You could work around this by manually converting your time coordinate to have units of ordinal months since some reference date, though it will have a somewhat tenuous physical meaning. Consider the following example:

>>> import pandas as pd; import xarray as xr
>>> times = pd.date_range("2000-05", periods=10, freq="7MS")
>>> da = xr.DataArray(range(10), dims=["time"], coords=[times])
>>> reference_date = da.time.min()
>>> months = da.time.dt.month
>>> years = da.time.dt.year
>>> ordinal_months = months + 12 *

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jesieleo
Comment options

@spencerkclark
Comment options

Answer selected by jesieleo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants