Skip to content

pandas/reindex-to-date-range

Rule reindex-to-date-range
Pack pandas
Severity warning
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions every version

Reindexing to a date_range from the first to the last time fills in missing steps by hand. Call asfreq with the frequency instead.

full = ts.reindex(pd.date_range(ts.index.min(), ts.index.max(), freq="15min"))
full = ts.asfreq("15min")

The rule reports ts.reindex(pd.date_range(ts.index.min(), ts.index.max(), freq="15min")), where asfreq fills in the missing steps in one call.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes ts.asfreq("15min").

The fix is unsafe, because asfreq keeps the name of the index and the reindex dropped it.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

asfreq fills in the missing steps between the first and the last time. Write $X.asfreq($F).

Browse the other rules of the pandas pack.