MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / cumOps

Method cumOps

src/danfojs-base/core/frame.ts:1724–1780  ·  view source on GitHub ↗
(ops: string, axis: number, inplace: boolean)

Source from the content-addressed store, hash-verified

1722 */
1723 private cumOps(ops: string, axis: number, inplace: boolean): DataFrame
1724 private cumOps(ops: string, axis: number, inplace: boolean): DataFrame | void {
1725 if (this.dtypes.includes("string")) ErrorThrower.throwStringDtypeOperationError(ops)
1726
1727 const result = this.$getDataByAxisWithMissingValuesRemoved(axis)
1728
1729 let newData: ArrayType2D = result.map((sData) => {
1730 let tempval = sData[0];
1731 const data = [tempval];
1732
1733 for (let i = 1; i < sData.length; i++) {
1734 let currVal = sData[i];
1735 switch (ops) {
1736 case "max":
1737 if (currVal > tempval) {
1738 data.push(currVal);
1739 tempval = currVal;
1740 } else {
1741 data.push(tempval);
1742 }
1743 break;
1744 case "min":
1745 if (currVal < tempval) {
1746 data.push(currVal);
1747 tempval = currVal;
1748 } else {
1749 data.push(tempval);
1750 }
1751 break;
1752 case "sum":
1753 tempval = (tempval as number) + (currVal as number)
1754 data.push(tempval);
1755 break;
1756 case "prod":
1757 tempval = (tempval as number) * (currVal as number)
1758 data.push(tempval);
1759 break;
1760
1761 }
1762 }
1763 return data;
1764 })
1765
1766 if (axis === 0) {
1767 newData = utils.transposeArray(newData) as ArrayType2D
1768 }
1769
1770 if (inplace) {
1771 this.$setValues(newData)
1772 } else {
1773 return new DataFrame(newData, {
1774 index: [...this.index],
1775 columns: [...this.columns],
1776 dtypes: [...this.dtypes],
1777 config: { ...this.config }
1778 })
1779 }
1780 }
1781

Callers 4

cumProdMethod · 0.95
cumSumMethod · 0.95
cumMinMethod · 0.95
cumMaxMethod · 0.95

Calls 5

includesMethod · 0.80
transposeArrayMethod · 0.80
$setValuesMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected