Skip to content

feat: add Series.toFrame - #709

Open
osazemeu wants to merge 1 commit into
javascriptdata:devfrom
osazemeu:feat/series-to-frame
Open

osazemeu wants to merge 1 commit into
javascriptdata:devfrom
osazemeu:feat/series-to-frame

Conversation

@osazemeu

@osazemeu osazemeu commented Dec 2, 2026

Copy link
Copy Markdown

Closes #619

Adds Series.toFrame(name?), which converts a Series to a one-column DataFrame, like pandas Series.to_frame.

const sf = new dfd.Series([10, 11, 12], { index: ["a", "b", "c"], columns: ["x"] });
sf.toFrame().columns        // [ 'x' ]
sf.toFrame().index          // [ 'a', 'b', 'c' ]
sf.toFrame("count").columns // [ 'count' ]

Behaviour

  • The DataFrame keeps the Series' index, dtype and config.
  • Column name: the name argument, else the Series' column name, else "0" (only an empty Series has no column name).
  • Index, dtypes and values are copied, so changing the DataFrame does not change the Series.

Changes

  • src/danfojs-base/core/series.ts: the method, with JSDoc and examples.
  • src/danfojs-base/shared/types.ts: toFrame in SeriesInterface.
  • Tests in the node and browser Series suites: values, index and dtype kept; the name argument; an explicit dtype that inference would not pick; df["a"].toFrame(); the "0" fallback and an empty Series; no shared state.

Verification

  • danfojs-node Series suite on Node 18.12.1: 218 passing.
  • On Node 24 the same suite has 4 failures in argMax/argMin, also present on dev: they call util.isNullOrUndefined, which Node 23 removed. CI runs Node 18 and 20, so it is not affected.
  • The browser suite was not run locally; CI runs it.

Notes

  • CONTRIBUTING.md asks for a CHANGELOG.md entry, but the repository has no CHANGELOG.md, so none is added.
  • The returned DataFrame is not instanceof the DataFrame exported by danfojs-node, as raised in the issue's comments. This is true of every method that returns a DataFrame (head(), getDummies(), column access), because they build the base class. It is left for a separate change.

Converts a Series to a one-column DataFrame, like pandas
Series.to_frame. The DataFrame keeps the Series' index, dtype and
config. The column is named after the optional name argument, else the
Series' column name, else "0".

Closes javascriptdata#619
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.

Series to DataFrame

1 participant