Skip to content

Commit b4f4ba2

Browse files
committed
Add prebuild script and update readme
1 parent 6ff001f commit b4f4ba2

10 files changed

Lines changed: 77 additions & 130 deletions

File tree

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
const tf = require("@tensorflow/tfjs")
2-
export default tf
1+
2+
// This file is auto-generated by prebuild.js. Do not edit!
3+
const tf = require("@tensorflow/tfjs")
4+
export default tf
5+

src/danfojs-browser/README.md

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ To use Danfo.js via script tags, copy and paste the CDN below to the body of you
5353
```html
5454
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.2.7/lib/bundle.min.js"></script>
5555
```
56+
### Example Usage in the Client Side Frameworks like React, Angular, Vue.js, etc.
57+
58+
> If you want to use Danfo in frontend frameworks like React/Vue, read this [guide](https://danfo.jsdata.org/examples/using-danfojs-in-react)
59+
60+
TODO:
5661

5762
### Example Usage in the Browser
5863

@@ -108,76 +113,11 @@ Output in Browser:
108113
Danfo.js is hosted on NPM, and can installed via package managers like npm and yarn
109114

110115
```sh
111-
npm install danfojs-node
112-
```
113-
114-
### Example usage in Nodejs
115-
116-
```javascript
117-
118-
const dfd = require("danfojs-node")
119-
120-
121-
dfd.read_csv("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv")
122-
.then(df => {
123-
//prints the first five columns
124-
df.head().print()
125-
126-
//Calculate descriptive statistics for all numerical columns
127-
df.describe().print()
128-
129-
//prints the shape of the data
130-
console.log(df.shape);
131-
132-
//prints all column names
133-
console.log(df.column_names);
134-
135-
//prints the inferred dtypes of each column
136-
df.ctypes.print()
137-
138-
//selecting a column by subsetting
139-
df['Name'].print()
140-
141-
//drop columns by names
142-
cols_2_remove = ['Age', 'Pclass']
143-
df_drop = df.drop({ columns: cols_2_remove, axis: 1 })
144-
df_drop.print()
145-
146-
147-
//select columns by dtypes
148-
let str_cols = df_drop.select_dtypes(["string"])
149-
let num_cols = df_drop.select_dtypes(["int32", "float32"])
150-
str_cols.print()
151-
num_cols.print()
152-
153-
154-
//add new column to Dataframe
155-
let new_vals = df['Fare'].round().values
156-
df_drop.addColumn({ column: "fare_round", value: new_vals})
157-
df_drop.print()
158-
159-
df_drop['fare_round'].print(5)
160-
161-
//prints the number of occurence each value in the column
162-
df_drop['Survived'].value_counts().print()
163-
164-
//print the last ten elementa of a DataFrame
165-
df_drop.tail(10).print()
166-
167-
//prints the number of missing values in a DataFrame
168-
df_drop.isna().sum().print()
169-
170-
}).catch(err => {
171-
console.log(err);
172-
})
173-
116+
npm install danfojs
174117
```
175-
Output in Node Console:
176-
177-
![](assets/node-rec.gif)
178-
179-
> If you want to use Danfo in frontend frameworks like React/Vue, read this [guide](https://danfo.jsdata.org/examples/using-danfojs-in-react)
180118

119+
### Danfo-js in Node.js
120+
To use Danfo.js in Node.js, you need to install the nodejs version (danfojs-node) via NPM/Yarn. See more information here.
181121
#### You can play with Danfo.js on Dnotebooks playground [here](https://playnotebook.jsdata.org/demo)
182122

183123
#### [See the Official Getting Started Guide](https://danfo.jsdata.org/getting-started)

src/danfojs-browser/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"scripts": {
3232
"test": "karma start --single-run --browsers ChromeHeadless karma.conf.js",
3333
"test:clean": "yarn build:clean && yarn run test",
34-
"build": "tsc && yarn run bundle",
35-
"build:clean": "rimraf ./dist && rimraf ./lib && yarn run build",
34+
"build": "node ./scripts/prebuild.js && tsc && yarn run bundle",
35+
"build:clean": "rimraf ./dist && rimraf ./lib && node ./scripts/prebuild.js && yarn run build",
3636
"dev": "nodemon",
3737
"lint": "eslint ./src",
3838
"bundle": "webpack --mode development",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright 2021, JsData. All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ==========================================================================
14+
*/
15+
16+
/**
17+
* Danfojs-node version uses Tensorflowjs-node package. Hence on bundling, we set the tensorflow lib
18+
* to use the Tensorflowjs-node package.
19+
* */
20+
21+
/* eslint-disable no-undef */
22+
const fs = require('fs');
23+
24+
function updateTensorflowLib(tensorflowLibPath) {
25+
const importStatement = `
26+
// This file is auto-generated by prebuild.js. Do not edit!
27+
const tf = require("@tensorflow/tfjs")\nexport default tf
28+
`;
29+
fs.writeFileSync(tensorflowLibPath, importStatement);
30+
}
31+
32+
updateTensorflowLib('../danfojs-base/shared/tensorflowlib.ts');

src/danfojs-node/README.md

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -47,63 +47,6 @@ easy and intuitive. It is heavily inspired by [Pandas](https://pandas.pydata.org
4747
- Robust data preprocessing functions like [OneHotEncoders](https://danfo.jsdata.org/api-reference/general-functions/danfo.onehotencoder), [LabelEncoders](https://danfo.jsdata.org/api-reference/general-functions/danfo.labelencoder), and scalers like [StandardScaler](https://danfo.jsdata.org/api-reference/general-functions/danfo.standardscaler) and [MinMaxScaler](https://danfo.jsdata.org/api-reference/general-functions/danfo.minmaxscaler) are supported on DataFrame and Series
4848

4949

50-
51-
To use Danfo.js via script tags, copy and paste the CDN below to the body of your HTML file
52-
53-
```html
54-
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.2.7/lib/bundle.min.js"></script>
55-
```
56-
57-
### Example Usage in the Browser
58-
59-
> See the example below in [Code Sandbox](https://codepen.io/risingodegua/pen/bGwPGMG)
60-
61-
```html
62-
63-
<!DOCTYPE html>
64-
<html lang="en">
65-
<head>
66-
<meta charset="UTF-8">
67-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
68-
<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
69-
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.2.7/lib/bundle.min.js"></script>
70-
71-
<title>Document</title>
72-
</head>
73-
74-
<body>
75-
76-
<div id="div1"></div>
77-
<div id="div2"></div>
78-
<div id="div3"></div>
79-
80-
<script>
81-
82-
dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
83-
.then(df => {
84-
85-
df['AAPL.Open'].plot("div1").box() //makes a box plot
86-
87-
df.plot("div2").table() //display csv as table
88-
89-
new_df = df.set_index({ key: "Date" }) //resets the index to Date column
90-
new_df.plot("div3").line({ columns: ["AAPL.Open", "AAPL.High"] }) //makes a timeseries plot
91-
92-
}).catch(err => {
93-
console.log(err);
94-
})
95-
96-
</script>
97-
98-
</body>
99-
100-
</html>
101-
```
102-
103-
Output in Browser:
104-
105-
![](assets/browser-out.gif)
106-
10750
## How to install
10851
Danfo.js is hosted on NPM, and can installed via package managers like npm and yarn
10952

src/danfojs-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"test:clean": "yarn build:clean && yarn test",
3434
"dev": "nodemon",
3535
"build": "tsc",
36-
"build:clean": "rimraf ./build && tsc",
36+
"build:clean": "rimraf ./build && node ./scripts/prebuild.js && tsc",
3737
"lint": "eslint ./src",
3838
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
3939
"coverage": "nyc report --reporter=text-lcov | coveralls && nyc report --reporter=lcov",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright 2021, JsData. All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
* ==========================================================================
14+
*/
15+
16+
/**
17+
* Danfojs-node version uses Tensorflowjs-node package. Hence on bundling, we set the tensorflow lib
18+
* to use the Tensorflowjs-node package.
19+
* */
20+
21+
/* eslint-disable no-undef */
22+
const fs = require('fs');
23+
24+
function updateTensorflowLib(tensorflowLibPath) {
25+
const importStatement = `const tf = require("@tensorflow/tfjs-node")\nexport default tf`;
26+
fs.writeFileSync(tensorflowLibPath, importStatement);
27+
}
28+
29+
updateTensorflowLib('../danfojs-base/shared/tensorflowlib.ts');
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)