FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add shift method to Series by mvanhorn · Pull Request #700 · javascriptdata/danfojs · GitHub

feat: add shift method to Series - #700

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

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

Conversation

mvanhorn commented Apr 8, 2026

Copy link
Copy Markdown

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL