Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add flow to Series. Add cummul, cummax, cummin for Series with tests
  • Loading branch information
mjclawar committed Mar 8, 2017
commit a5ab4ef75fe920bec6a17ecdaa00e3cd5a23eb69
38 changes: 32 additions & 6 deletions src/es6/__tests__/core/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,38 @@ describe('series', () => {
});
});

describe('cumsum', () => {
const ds = new Series([1, 2, 3, 4, 5], {index: [2, 3, 4, 5, 6]});
const ds2 = ds.cumsum();
expect(ds2).toBeInstanceOf(Series);
expect(ds2.values.toArray()).toEqual([1, 3, 6, 10, 15]);
expect(ds2.index.toArray()).toEqual([2, 3, 4, 5, 6]);
describe('cumulative functions', () => {
it('cumsum', () => {
const ds = new Series([1, 2, 3, 4, 5], {index: [2, 3, 4, 5, 6]});
const ds2 = ds.cumsum();
expect(ds2).toBeInstanceOf(Series);
expect(ds2.values.toArray()).toEqual([1, 3, 6, 10, 15]);
expect(ds2.index.toArray()).toEqual([2, 3, 4, 5, 6]);
});

it('cummul', () => {
const ds = new Series([1, 2, 3, 4, 5], {index: [2, 3, 4, 5, 6]});
const ds2 = ds.cummul();
expect(ds2).toBeInstanceOf(Series);
expect(ds2.values.toArray()).toEqual([1, 2, 6, 24, 120]);
expect(ds2.index.toArray()).toEqual([2, 3, 4, 5, 6]);
});

it('cummax', () => {
const ds = new Series([1, 2, 6, 4, 5], {index: [2, 3, 4, 5, 6]});
const ds2 = ds.cummax();
expect(ds2).toBeInstanceOf(Series);
expect(ds2.values.toArray()).toEqual([1, 2, 6, 6, 6]);
expect(ds2.index.toArray()).toEqual([2, 3, 4, 5, 6]);
});

it('cummin', () => {
const ds = new Series([3, 2, 6, 1, 5], {index: [2, 3, 4, 5, 6]});
const ds2 = ds.cummin();
expect(ds2).toBeInstanceOf(Series);
expect(ds2.values.toArray()).toEqual([3, 2, 2, 1, 1]);
expect(ds2.index.toArray()).toEqual([2, 3, 4, 5, 6]);
});
});
});
});
11 changes: 6 additions & 5 deletions src/es6/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default class DataFrame extends NDFrame {
return new DataFrame(this._data.set(column, series), this.kwargs);
else if (series instanceof Immutable.List || Array.isArray(series))
return new DataFrame(this._data.set(
column,
column, // $FlowIssue TODO
new Series(series, {index: this.index, name: column})), this.kwargs);
throw new TypeError('series must be a Series!');
}
Expand Down Expand Up @@ -804,7 +804,7 @@ export default class DataFrame extends NDFrame {
csvString += '\r\n';

const updateString = (idx) => {
let s = '';
let s = ''; // $FlowIssue TODO
this.columns.forEach((k) => { s += `${this.get(k).iloc(idx)},`; });
return s;
};
Expand Down Expand Up @@ -1165,7 +1165,7 @@ export default class DataFrame extends NDFrame {
* // Returns DataFrame([{x: 1, y: -1, z: 2}, {x: -1, y: 1, z: -2}, {x: 2, y: -2, z: 4}])
* df.cov();
*/
cov(): DataFrame {
cov(): DataFrame { // $FlowIssue TODO
return this._pairwiseDataFrame((ds1, ds2) => ds1.cov(ds2));
}

Expand All @@ -1184,7 +1184,7 @@ export default class DataFrame extends NDFrame {
*/
corr(): DataFrame {
// noinspection Eslint
const corrFunc = (ds1, ds2) => {
const corrFunc = (ds1, ds2) => { // $FlowIssue TODO
return ds1.values === ds2.values ? 1 : ds1.corr(ds2);
};
return this._pairwiseDataFrame(corrFunc);
Expand Down Expand Up @@ -1228,7 +1228,7 @@ export default class DataFrame extends NDFrame {
if (idx < periods)
return [k, new Series(Immutable.Repeat(null, this.length).toList(),
{name: k, index: this.index})];
const compareCol = this.get(this.columns.get(idx - periods));
const compareCol = this.get(this.columns.get(idx - periods)); // $FlowIssue TODO
return [k, this.get(k).map((v, vIdx) => v - compareCol.iloc(vIdx))];
})), {index: this.index});
}
Expand Down Expand Up @@ -1275,6 +1275,7 @@ export default class DataFrame extends NDFrame {
return [k, new Series(Immutable.Repeat(null, this.length).toList(),
{name: k, index: this.index})];
const compareCol = this.get(this.columns.get(idx - periods));
// $FlowIssue TODO
return [k, this.get(k).map((v, vIdx) => (v / compareCol.iloc(vIdx)) - 1)];
})), {index: this.index});
}
Expand Down
Loading