Skip to content

Commit a8d14d4

Browse files
authored
Merge pull request #438 from javascriptdata/fix/breaking-import
Fix/breaking import
2 parents 05d5470 + c1bd5d9 commit a8d14d4

File tree

15 files changed

+705
-540
lines changed

15 files changed

+705
-540
lines changed

src/danfojs-base/core/frame.ts

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
* limitations under the License.
1313
* ==========================================================================
1414
*/
15-
import { toCSVBrowser, toExcelBrowser, toJSONBrowser } from "../io/browser";
16-
import { toCSVNode, toExcelNode, toJSONNode } from "../io/node";
1715
import dummyEncode from "../transformers/encoders/dummy.encoder";
1816
import { variance, std, median, mode, mean } from 'mathjs';
1917
import tensorflow from '../shared/tensorflowlib'
@@ -22,7 +20,6 @@ import { _genericMathOp } from "./math.ops";
2220
import Groupby from '../aggregators/groupby';
2321
import ErrorThrower from "../shared/errors"
2422
import { _iloc, _loc } from "./indexing";
25-
import { PlotlyLib } from "../plotting";
2623
import Utils from "../shared/utils"
2724
import NDframe from "./generic";
2825
import { table } from "table";
@@ -32,12 +29,6 @@ import {
3229
ArrayType2D,
3330
DataFrameInterface,
3431
BaseDataOptionType,
35-
CsvOutputOptionsBrowser,
36-
ExcelOutputOptionsBrowser,
37-
JsonOutputOptionsBrowser,
38-
CsvOutputOptionsNode,
39-
ExcelOutputOptionsNode,
40-
JsonOutputOptionsNode
4132
} from "../shared/types";
4233

4334
const utils = new Utils();
@@ -3368,172 +3359,6 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
33683359

33693360
}
33703361

3371-
/**
3372-
* Exposes functions for creating charts from a DataFrame.
3373-
* Charts are created using the Plotly.js library, so all Plotly's configuration parameters are available.
3374-
* @param divId name of the HTML Div to render the chart in.
3375-
*/
3376-
plot(divId: string) {
3377-
//TODO: Add support for check plot library to use. So we can support other plot library like d3, vega, etc
3378-
if (utils.isBrowserEnv()) {
3379-
const plt = new PlotlyLib(this, divId);
3380-
return plt;
3381-
} else {
3382-
throw new Error("Not supported in NodeJS");
3383-
}
3384-
}
3385-
3386-
/**
3387-
* Converts a DataFrame to CSV.
3388-
* @param options Configuration object. Supports the following options:
3389-
* - `filePath`: Local file path to write the CSV file. If not specified, the CSV will be returned as a string. Option is only available in NodeJS.
3390-
* - `fileName`: Name of the CSV file. Defaults to `data.csv`. Option is only available in Browser.
3391-
* - `download`: If true, the CSV will be downloaded. Defaults to false. Option is only available in Browser.
3392-
* - `header`: Boolean indicating whether to include a header row in the CSV file.
3393-
* - `sep`: Character to be used as a separator in the CSV file.
3394-
*
3395-
* @example
3396-
* ```
3397-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3398-
* const csv = df.toCSV()
3399-
* console.log(csv)
3400-
* //output
3401-
* "A","B"
3402-
* 1,2
3403-
* 3,4
3404-
* ```
3405-
*
3406-
* @example
3407-
* ```
3408-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3409-
* const csv = df.toCSV({ header: false })
3410-
* console.log(csv)
3411-
* //output
3412-
* 1,2
3413-
* 3,4
3414-
* ```
3415-
*
3416-
* @example
3417-
* ```
3418-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3419-
* const csv = df.toCSV({ sep: ';' })
3420-
* console.log(csv)
3421-
* //output
3422-
* "A";"B"
3423-
* 1;2
3424-
* 3;4
3425-
* ```
3426-
*
3427-
* @example
3428-
* ```
3429-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3430-
* df.toCSV({ filePath: './data.csv' }) //write to local file in NodeJS
3431-
* ```
3432-
*
3433-
* @example
3434-
* ```
3435-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3436-
* df.toCSV({ fileName: 'data.csv', download: true }) //Downloads file in Browser
3437-
* ```
3438-
*
3439-
*/
3440-
toCSV(options?: CsvOutputOptionsBrowser | CsvOutputOptionsNode): string
3441-
toCSV(options?: CsvOutputOptionsBrowser | CsvOutputOptionsNode): string | void {
3442-
if (utils.isBrowserEnv()) {
3443-
return toCSVBrowser(this, options as CsvOutputOptionsBrowser)
3444-
} else {
3445-
return toCSVNode(this, options as CsvOutputOptionsNode)
3446-
}
3447-
}
3448-
3449-
/**
3450-
* Converts a DataFrame to JSON.
3451-
* @param options Configuration object. Supported options:
3452-
* - `filePath`: The file path to write the JSON to. If not specified, the JSON object is returned. Option is only available in NodeJS.
3453-
* - `fileName`: The name of the JSON file. Defaults to `data.json`. Option is only available in Browser.
3454-
* - `download`: If true, the JSON will be downloaded. Defaults to false. Option is only available in Browser.
3455-
* - `format`: The format of the JSON. Supported values are `'column'` and `'row'`. Defaults to `'column'`.
3456-
*
3457-
* @example
3458-
* ```
3459-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3460-
* const json = df.toJSON()
3461-
* ```
3462-
*
3463-
* @example
3464-
* ```
3465-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3466-
* const json = df.toJSON({ format: 'row' })
3467-
* console.log(json)
3468-
* //output
3469-
* [{"A":1,"B":2},{"A":3,"B":4}]
3470-
* ```
3471-
*
3472-
* @example
3473-
* ```
3474-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3475-
* const json = df.toJSON({ format: "column" })
3476-
* console.log(json)
3477-
* //output
3478-
* {"A":[1,3],"B":[2,4]}
3479-
* ```
3480-
*
3481-
* @example
3482-
* ```
3483-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3484-
* df.toJSON({ filePath: './data.json' }) // downloads to local file system as data.json in NodeJS
3485-
* ```
3486-
*
3487-
* @example
3488-
* ```
3489-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3490-
* df.toJSON({ fileName: 'data.json', download: true }) // downloads file browser
3491-
* ```
3492-
*/
3493-
toJSON(options?: JsonOutputOptionsBrowser | JsonOutputOptionsNode): object
3494-
toJSON(options?: JsonOutputOptionsBrowser | JsonOutputOptionsNode): object | void {
3495-
if (utils.isBrowserEnv()) {
3496-
return toJSONBrowser(this, options as JsonOutputOptionsBrowser)
3497-
} else {
3498-
return toJSONNode(this, options as JsonOutputOptionsNode)
3499-
}
3500-
}
3501-
3502-
3503-
/**
3504-
* Converts a DataFrame to Excel file format.
3505-
* @param options Configuration object. Supported options:
3506-
* - `sheetName`: The sheet name to be written to. Defaults to `'Sheet1'`.
3507-
* - `filePath`: The filePath to be written to. Defaults to `'./output.xlsx'`. Option is only available in NodeJs
3508-
* - `fileName`: The fileName to be written to. Defaults to `'output.xlsx'`. Option is only available in Browser
3509-
*
3510-
* @example
3511-
* ```
3512-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3513-
* df.toExcel({ filePath: './output.xlsx' }) // writes to local file system as output.xlsx in NodeJS
3514-
* ```
3515-
*
3516-
* @example
3517-
* ```
3518-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3519-
* df.toExcel({ fileName: 'output.xlsx', download: true }) // downloads file browser
3520-
* ```
3521-
*
3522-
* @example
3523-
* ```
3524-
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3525-
* df.toExcel({ sheetName: 'Sheet2' }) // writes to Sheet2 in Excel
3526-
* ```
3527-
*
3528-
*/
3529-
toExcel(options?: ExcelOutputOptionsBrowser | ExcelOutputOptionsNode): void {
3530-
if (utils.isBrowserEnv()) {
3531-
toExcelBrowser(this, options as ExcelOutputOptionsBrowser)
3532-
} else {
3533-
return toExcelNode(this, options as ExcelOutputOptionsNode)
3534-
}
3535-
}
3536-
35373362
/**
35383363
* Access a single value for a row/column pair by integer position.
35393364
* Similar to {@link iloc}, in that both provide integer-based lookups.

src/danfojs-base/core/series.ts

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
* limitations under the License.
1313
* ==========================================================================
1414
*/
15-
import { toCSVBrowser, toExcelBrowser, toJSONBrowser } from "../io/browser";
16-
import { toCSVNode, toExcelNode, toJSONNode } from "../io/node";
1715
import dummyEncode from "../transformers/encoders/dummy.encoder";
1816
import { variance, std, median, mode } from 'mathjs';
1917
import tensorflow from '../shared/tensorflowlib'
2018
import { DATA_TYPES } from '../shared/defaults'
2119
import { _genericMathOp } from "./math.ops";
2220
import ErrorThrower from "../shared/errors"
2321
import { _iloc, _loc } from "./indexing";
24-
import { PlotlyLib } from "../plotting";
2522
import Utils from "../shared/utils"
2623
import NDframe from "./generic";
2724
import { table } from "table";
@@ -32,12 +29,6 @@ import {
3229
ArrayType1D,
3330
BaseDataOptionType,
3431
SeriesInterface,
35-
CsvOutputOptionsBrowser,
36-
ExcelOutputOptionsBrowser,
37-
JsonOutputOptionsBrowser,
38-
CsvOutputOptionsNode,
39-
ExcelOutputOptionsNode,
40-
JsonOutputOptionsNode,
4132
mapParam
4233
} from "../shared/types";
4334

@@ -194,7 +185,7 @@ export default class Series extends NDframe implements SeriesInterface {
194185
if (this.shape[0] - rows < 0) {
195186
throw new Error("ParamError: Number of rows cannot be greater than available rows in data")
196187
}
197-
188+
198189
const startIdx = this.shape[0] - rows
199190
return this.iloc([`${startIdx}:`])
200191
}
@@ -2137,136 +2128,6 @@ export default class Series extends NDframe implements SeriesInterface {
21372128
return dummyEncode(this, options)
21382129
}
21392130

2140-
2141-
/**
2142-
* Exposes functions for creating charts from a Series.
2143-
* Charts are created using the Plotly.js library, so all Plotly's configuration parameters are available.
2144-
* @param divId name of the HTML Div to render the chart in.
2145-
* @example
2146-
* ```
2147-
* const sf = new Series([1, 2, 3, 4, 5]);
2148-
* sf.plot("myDiv").line() //renders the chart in the div with id "myDiv"
2149-
* ```
2150-
*/
2151-
plot(divId: string) {
2152-
//TODO: Add support for check plot library to use
2153-
// So we can support other plot library like d3, vega, etc
2154-
if (utils.isBrowserEnv()) {
2155-
const plt = new PlotlyLib(this, divId);
2156-
return plt;
2157-
} else {
2158-
throw new Error("Not supported in NodeJS");
2159-
}
2160-
}
2161-
2162-
/**
2163-
* Converts a Series to CSV.
2164-
* @param options Configuration object. Supports the following options:
2165-
* - `filePath`: Local file path to write the CSV file. If not specified, the CSV will be returned as a string. Option is only available in NodeJS.
2166-
* - `fileName`: Name of the CSV file. Defaults to `data.csv`. Option is only available in Browser.
2167-
* - `download`: If true, the CSV will be downloaded. Defaults to false. Option is only available in Browser.
2168-
*
2169-
* @example
2170-
* ```
2171-
* const df = new Series([1, 2, 3, 4])
2172-
* const csv = df.toCSV()
2173-
* console.log(csv)
2174-
* //output "1,2,3,4"
2175-
* ```
2176-
*
2177-
* @example
2178-
* ```
2179-
* const df = new Series([1, 2, 3, 4])
2180-
* df.toCSV({ filePath: './data.csv' }) //write to local file in NodeJS
2181-
* ```
2182-
*
2183-
* @example
2184-
* ```
2185-
* const df = new Series([1, 2, 3, 4])
2186-
* df.toCSV({ fileName: 'data.csv', download: true }) //Downloads file in Browser
2187-
* ```
2188-
*
2189-
*/
2190-
toCSV(options?: CsvOutputOptionsBrowser | CsvOutputOptionsNode): string
2191-
toCSV(options?: CsvOutputOptionsBrowser | CsvOutputOptionsNode): string | void {
2192-
if (utils.isBrowserEnv()) {
2193-
return toCSVBrowser(this, options as CsvOutputOptionsBrowser)
2194-
} else {
2195-
return toCSVNode(this, options as CsvOutputOptionsNode)
2196-
}
2197-
}
2198-
2199-
/**
2200-
* Converts a Series to JSON.
2201-
* @param options Configuration object. Supported options:
2202-
* - `filePath`: The file path to write the JSON to. If not specified, the JSON object is returned. Option is only available in NodeJS.
2203-
* - `fileName`: The name of the JSON file. Defaults to `data.json`. Option is only available in Browser.
2204-
* - `download`: If true, the JSON will be downloaded. Defaults to false. Option is only available in Browser.
2205-
*
2206-
* @example
2207-
* ```
2208-
* const df = new Series([[1, 2, 3, 4]], { columns: ['A']})
2209-
* const json = df.toJSON()
2210-
* console.log(json)
2211-
* //output { A: [ '1,2,3,4' ] }
2212-
* ```
2213-
*
2214-
* @example
2215-
* ```
2216-
* const df = new Series([1, 2, 3, 4])
2217-
* df.toJSON({ filePath: './data.json' }) // downloads to local file system as data.json in NodeJS
2218-
* ```
2219-
*
2220-
* @example
2221-
* ```
2222-
* const df = new Series([1, 2, 3, 4])
2223-
* df.toJSON({ fileName: 'data.json', download: true }) // downloads file browser
2224-
* ```
2225-
*/
2226-
toJSON(options?: JsonOutputOptionsBrowser | JsonOutputOptionsNode): object
2227-
toJSON(options?: JsonOutputOptionsBrowser | JsonOutputOptionsNode): object | void {
2228-
if (utils.isBrowserEnv()) {
2229-
return toJSONBrowser(this, options as JsonOutputOptionsBrowser)
2230-
} else {
2231-
return toJSONNode(this, options as JsonOutputOptionsNode)
2232-
}
2233-
}
2234-
2235-
2236-
/**
2237-
* Converts a Series to Excel file format.
2238-
* @param options Configuration object. Supported options:
2239-
* - `sheetName`: The sheet name to be written to. Defaults to `'Sheet1'`.
2240-
* - `filePath`: The filePath to be written to. Defaults to `'./output.xlsx'`. Option is only available in NodeJs
2241-
* - `fileName`: The fileName to be written to. Defaults to `'output.xlsx'`. Option is only available in Browser
2242-
*
2243-
* @example
2244-
* ```
2245-
* const df = new Series([1, 2, 3, 4])
2246-
* df.toExcel({ filePath: './output.xlsx' }) // writes to local file system as output.xlsx in NodeJS
2247-
* ```
2248-
*
2249-
* @example
2250-
* ```
2251-
* const df = new Series([1, 2, 3, 4])
2252-
* df.toExcel({ fileName: 'output.xlsx', download: true }) // downloads file browser
2253-
* ```
2254-
*
2255-
* @example
2256-
* ```
2257-
* const df = new Series([1, 2, 3, 4])
2258-
* df.toExcel({ sheetName: 'Sheet2' }) // writes to Sheet2 in Excel
2259-
* ```
2260-
*
2261-
*/
2262-
toExcel(options?: ExcelOutputOptionsBrowser | ExcelOutputOptionsNode): void {
2263-
if (utils.isBrowserEnv()) {
2264-
toExcelBrowser(this, options as ExcelOutputOptionsBrowser)
2265-
} else {
2266-
return toExcelNode(this, options as ExcelOutputOptionsNode)
2267-
}
2268-
}
2269-
22702131
/**
22712132
* Access a single value for a row index.
22722133
* Similar to iloc, in that both provide index-based lookups.

0 commit comments

Comments
 (0)