Skip to content

feat: add shift method to Series#700

Open
mvanhorn wants to merge 1 commit intojavascriptdata:devfrom
mvanhorn:feat/series-shift
Open

feat: add shift method to Series#700
mvanhorn wants to merge 1 commit intojavascriptdata:devfrom
mvanhorn:feat/series-shift

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Apr 8, 2026

Summary

Adds Series.shift(periods, options) matching the pandas Series.shift() API. Requested in #617.

The method shifts values by N positions and fills the gap with NaN (or a custom fillValue).

const sf = new Series([1, 2, 3, 4, 5]);
sf.shift(1).values;   // [NaN, 1, 2, 3, 4]
sf.shift(-1).values;  // [2, 3, 4, 5, NaN]
sf.shift(2, { fillValue: 0 }).values;  // [0, 0, 1, 2, 3]

Changes

  • src/danfojs-base/core/series.ts: new shift() method after tail(), follows the same pattern (jsdoc, copy semantics, index preservation)
  • src/danfojs-node/test/core/series.test.ts: 5 test cases covering shift down, shift up, zero shift, custom fill, and overflow

Fixes #617

This contribution was developed with AI assistance (Codex).

Implements Series.shift(periods, options) matching the pandas API.
Supports positive/negative periods and custom fillValue.
Includes tests for all edge cases.

Fixes javascriptdata#617
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shift is missing for Series

1 participant