Skip to content

Commit

Permalink
Node docs (#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
universalmind303 committed Dec 31, 2021
1 parent ed20228 commit b8957ce
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 51 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ jobs:
toolchain: nightly-2021-12-02
override: true
components: rustfmt, clippy
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 16
- name: Build node reference
run: |
cd nodejs-polars
npm install
npx typedoc
- name: Set up Python
uses: actions/setup-python@v2
with:
Expand All @@ -34,7 +43,9 @@ jobs:
RUSTFLAGS="--cfg docsrs" cargo doc --features=docs-selection --package polars && \
echo '<meta http-equiv=refresh content=0;url=polars/index.html>' > target/doc/index.html && \
mkdir target/doc/py-polars
mkdir -p target/doc/nodejs-polars/html
cp -r py-polars/docs/build/html target/doc/py-polars
cp -r nodejs-polars/docs/* target/doc/nodejs-polars/html
echo ghp-import step
ghp-import -n target/doc && \
git push -qf https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git gh-pages
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Build and test](https://github.com/pola-rs/polars/workflows/Build%20and%20test/badge.svg)](https://github.com/pola-rs/polars/actions)
[![](https://img.shields.io/crates/v/polars.svg)](https://crates.io/crates/polars)
[![PyPI Latest Release](https://img.shields.io/pypi/v/polars.svg)](https://pypi.org/project/polars/)
[![NPM Latest Release](https://img.shields.io/npm/v/nodejs-polars.svg)](https://www.npmjs.com/package/nodejs-polars)

<p align="center">
<a href="https://pola-rs.github.io/polars/py-polars/html/reference/index.html">Python Documentation</a>
Expand Down Expand Up @@ -135,6 +136,12 @@ Want to know about all the features Polars supports? Read the docs!
* [Rust documentation (master branch)](https://pola-rs.github.io/polars/polars/index.html)
* [User guide](https://pola-rs.github.io/polars-book/)

#### Node

* Installation guide: `$ yarn install nodejs-polars`
* [Node documentation](https://pola-rs.github.io/polars/nodejs-polars/html/index.html)
* [User guide](https://pola-rs.github.io/polars-book/)


## Contribution

Expand Down
8 changes: 6 additions & 2 deletions nodejs-polars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Build and test](https://github.com/pola-rs/polars/workflows/Build%20and%20test/badge.svg)](https://github.com/pola-rs/polars/actions)
[![](https://img.shields.io/crates/v/polars.svg)](https://crates.io/crates/polars)
[![PyPI Latest Release](https://img.shields.io/pypi/v/polars.svg)](https://pypi.org/project/polars/)
[![NPM Latest Release](https://img.shields.io/npm/v/nodejs-polars.svg)](https://www.npmjs.com/package/nodejs-polars)

## Usage

Expand Down Expand Up @@ -109,6 +110,7 @@ $ npm i -s nodejs-polars # npm

Releases happen quite often (weekly / every few days) at the moment, so updating polars regularly to get the latest bugfixes / features might not be a bad idea.

___
#### Rust version

Required Rust version `>=1.52`
Expand All @@ -128,9 +130,11 @@ Want to know about all the features Polars supports? Read the docs!
- [Rust documentation (master branch)](https://pola-rs.github.io/polars/polars/index.html)
- [User guide](https://pola-rs.github.io/polars-book/)

### Node
#### Node

- **COMING SOON!**
* Installation guide: `$ yarn install nodejs-polars`
* [Node documentation](https://pola-rs.github.io/polars/nodejs-polars/html/index.html)
* [User guide](https://pola-rs.github.io/polars-book/)

## Contribution

Expand Down
19 changes: 4 additions & 15 deletions nodejs-polars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"bin"
],
"keywords": [
"csv",
"transform",
"parse",
"json",
"polars",
"dataframe",
"data-processing",
Expand Down Expand Up @@ -77,21 +81,6 @@
"dependencies": {
"@node-rs/helper": "^1.2.1"
},
"lint-staged": {
"*.@(js|ts|tsx)": [
"eslint -c .eslintrc.yml --fix"
],
"*.@(js|ts|tsx|yml|yaml|md|json)": [
"prettier --parser yaml --write"
]
},
"prettier": {
"printWidth": 80,
"semi": true,
"trailingComma": "none",
"singleQuote": true,
"arrowParens": "always"
},
"packageManager": "yarn@3.1.1",
"workspaces": [
"benches"
Expand Down
3 changes: 1 addition & 2 deletions nodejs-polars/polars/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Config {
/** Turn off the global string cache */
unsetGlobalStringCache(): Config
}
export const Config = {
export const Config: Config = {
setUtf8Tables() {
delete process.env["POLARS_FMT_NO_UTF8"];

Expand Down Expand Up @@ -47,5 +47,4 @@ export const Config = {
unsetGlobalStringCache() {
return this;
}

};
11 changes: 6 additions & 5 deletions nodejs-polars/polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const inspect = Symbol.for("nodejs.util.inspect.custom");


export interface DataFrame {
(column: string): Series<any>,
(column: string, ...columns: string[]): DataFrame,
(row: number): any[]
/** @ignore */
_df: JsDataFrame
dtypes: DataType[]
height: number
Expand Down Expand Up @@ -607,6 +605,7 @@ export interface DataFrame {
* Create a new DataFrame that shows the null counts per column.
* ___
* @example
* ```
* >>> df = pl.DataFrame({
* >>> "foo": [1, null, 3],
* >>> "bar": [6, 7, null],
Expand All @@ -621,6 +620,7 @@ export interface DataFrame {
* ╞═════╪═════╪═════╡
* │ 1 ┆ 1 ┆ 0 │
* └─────┴─────┴─────┘
* ```
*/
nullCount(): DataFrame
/**
Expand Down Expand Up @@ -1217,6 +1217,9 @@ function map<T>(df: DataFrame, fn: (...args: any[]) => T[]) {
return df.rows().map(fn);
}

/**
* @ignore
*/
export const dfWrapper = (_df: JsDataFrame): DataFrame => {
const unwrap = <U>(method: string, args?: object, df=_df): U => {

Expand Down Expand Up @@ -1715,8 +1718,6 @@ export const dfWrapper = (_df: JsDataFrame): DataFrame => {

};

export const _wrapDataFrame = (df, method, args) => dfWrapper(pli.df[method]({_df: df, ...args }));


/**
*
Expand Down
18 changes: 8 additions & 10 deletions nodejs-polars/polars/groupby.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* eslint-disable no-redeclare */
import {DataFrame, dfWrapper, _wrapDataFrame} from "./dataframe";
import {DataFrame, dfWrapper} from "./dataframe";
import * as utils from "./utils";
import type {ColumnSelection} from "./utils";
const inspect = Symbol.for("nodejs.util.inspect.custom");
import util from "util";
import {InvalidOperationError, todo} from "./error";
import {InvalidOperationError} from "./error";
import {Expr} from "./lazy/expr";
import {col, exclude} from "./lazy/functions";
import pli from "./internals/polars_internal";


import {col, exclude} from "./lazy/lazy_functions";

const inspect = Symbol.for("nodejs.util.inspect.custom");
const inspectOpts = {colors:true, depth:null};

/**
Expand Down Expand Up @@ -224,9 +222,9 @@ export function GroupBy(
agg,
pivot,
aggList: () => agg(exclude(by as any).list()),
count: () => _wrapDataFrame(df, "groupby", {by, agg: "count"}),
count: () => dfWrapper(pli.df.groupby({by, agg: "count", _df: df})),
first: () => agg(exclude(by as any).first()),
groups: () => _wrapDataFrame(df, "groupby", {by, agg: "groups"}),
groups: () => dfWrapper(pli.df.groupby({by, agg: "groups", _df: df})),
head: (n=5) => agg(exclude(by as any).head(n)),
last: () => agg(exclude(by as any).last()),
max: () => agg(exclude(by as any).max()),
Expand All @@ -248,7 +246,7 @@ function PivotOps(
valueCol: string
): PivotOps {

const pivot = (agg) => () => _wrapDataFrame(df, "pivot", {by, pivotCol, valueCol, agg});
const pivot = (agg) => () => dfWrapper(pli.df.pivot({by, pivotCol, valueCol, agg, _df: df}));
const customInspect = () => util.formatWithOptions(inspectOpts, "PivotOps {by: %O}", by);

return {
Expand Down
10 changes: 5 additions & 5 deletions nodejs-polars/polars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ import * as cfg from "./cfg";
import {version as _version} from "../package.json";

import type { FillNullStrategy as _FillNullStrategy } from "./utils";
import {
import {
funcs as lazy,
Expr as lazyExpr,
GroupBy as lazyGroupBy,
when as _when
} from "./lazy";

namespace pl {

export type Expr = lazyExpr
export import Expr = lazyExpr.Expr
export import DataFrame = df.DataFrame
export import Series = series.Series;
export type LazyGroupBy = lazyGroupBy;
export type When = _when.When;
export type WhenThen = _when.WhenThen;
export type WhenThenThen = _when.WhenThenThen;
export type FillNullStrategy = _FillNullStrategy;
export import Config = cfg.Config;
export import DataFrame = df.DataFrame
export import Series = series.Series;
export import Int16 = DataType.Int16
export import Int32 = DataType.Int32;
export import Int64 = DataType.Int64;
Expand Down Expand Up @@ -84,4 +83,5 @@ namespace pl {
export import when = _when.when;
export const version = _version;
}

export = pl;
1 change: 1 addition & 0 deletions nodejs-polars/polars/lazy/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type LazyOptions = {
*/

export interface LazyDataFrame {
/** @ignore */
_ldf: any;
get columns(): string[]
/**
Expand Down
4 changes: 3 additions & 1 deletion nodejs-polars/polars/lazy/expr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DataType} from "../datatypes";
import pli from "../internals/polars_internal";
import {col, lit} from "./lazy_functions";
import {col, lit} from "./functions";
import {
ExprOrString,
FillNullStrategy,
Expand Down Expand Up @@ -252,6 +252,7 @@ export interface ExprDateTimeFunctions {
}

export interface Expr {
/** @ignore */
_expr: any;
get date(): ExprDateTimeFunctions;
get str(): ExprStringFunctions;
Expand Down Expand Up @@ -1223,6 +1224,7 @@ const _Expr = (_expr: JsExpr): Expr => {
const isExpr = (anyVal: any): anyVal is Expr => isExternal(anyVal?._expr);
export const Expr = Object.assign(_Expr, {isExpr});

/** @ignore */
export const exprToLitOrExpr = (expr: any, stringToLit = true): Expr => {
if(typeof expr === "string" && !stringToLit) {
return col(expr);
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions nodejs-polars/polars/lazy/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

import * as func from "./lazy_functions";
import * as func from "./functions";
import * as gb from "./groupby";
import * as expr from "./expr";
import * as whenthen from "./whenthen";

namespace lazy {
export import GroupBy = gb.LazyGroupBy;
export import Expr = expr.Expr;
export import funcs = func
export import when = whenthen
export import Expr = expr;
export import funcs = func;
export import when = whenthen;
}

export = lazy;
9 changes: 6 additions & 3 deletions nodejs-polars/polars/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ListFunctions} from "./series/list";
import {DateTimeFunctions} from "./series/datetime";
import {InvalidOperationError, todo} from "./error";
import {RankMethod, RollingOptions} from "./utils";
import {col} from "./lazy/lazy_functions";
import {col} from "./lazy/functions";
import {isExternal} from "util/types";

const inspect = Symbol.for("nodejs.util.inspect.custom");
Expand All @@ -16,14 +16,17 @@ type ValueOrNever<V> = V extends ArrayLike<infer U> ? Series<U> : never;
type DataTypeOrValue<T, U> = U extends true ? DtypeToPrimitive<T> : DtypeToPrimitive<T> | null;
type ArrayLikeDataType<T> = ArrayLike<DtypeToPrimitive<T>>
type ArrayLikeOrDataType<T, U> = ArrayLike<DataTypeOrValue<T, U>>

/** @ignore */
export type JsSeries = any;

export interface Series<T> extends ArrayLike<T> {
[n: number]: T
/** @ignore */
_series: JsSeries;
name: string
dtype: DataType
length: number
_series: JsSeries;
str: StringFunctions
lst: ListFunctions<T>
date: DateTimeFunctions
Expand Down Expand Up @@ -1240,7 +1243,7 @@ export interface Series<T> extends ArrayLike<T> {
toJS(): {name: string, datatype: string, values: any[]}
toFrame(): DataFrame
}

/** @ignore */
export const seriesWrapper = <T>(_s: JsSeries): Series<T> => {
const unwrap = <U>(method: string, args?: object, _series = _s): U => {

Expand Down
2 changes: 1 addition & 1 deletion nodejs-polars/polars/series/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {JsSeries, Series, seriesWrapper} from "../series";
import {col} from "../lazy/lazy_functions";
import {col} from "../lazy/functions";

export interface ListFunctions<T> {
get(index: number): Series<T>
Expand Down
2 changes: 1 addition & 1 deletion nodejs-polars/polars/series/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pli from "../internals/polars_internal";
import {DataType} from "../datatypes";
import {JsSeries, Series, seriesWrapper} from "../series";
import {regexToString} from "../utils";
import {col} from "../lazy/lazy_functions";
import {col} from "../lazy/functions";


/**
Expand Down
11 changes: 10 additions & 1 deletion nodejs-polars/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@
"polars/series.ts",
"polars/dataframe.ts",
"polars/groupby.ts",
"polars/index.ts"
"polars/io.ts",
"polars/cfg.ts",
"polars/lazy/expr.ts",
"polars/lazy/dataframe.ts",
"polars/lazy/functions.ts",
"polars/lazy/groupby.ts",
"polars/lazy/whenthen.ts",
"polars/series/datetime.ts",
"polars/series/string.ts",
"polars/series/list.ts"
],
"out": "docs"
}
Expand Down

0 comments on commit b8957ce

Please sign in to comment.