Merge branch 'dev' · javascriptdata/danfojs@d3df3a3 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit d3df3a3

Browse files
committed
Merge branch 'dev'
2 parents d267db6 + 0d33e34 commit d3df3a3

File tree

22 files changed

+936
-528
lines changed

22 files changed

+936
-528
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ yarn add danfojs
7070
For use directly in HTML files, you can add the latest script tag from [JsDelivr](https://www.jsdelivr.com/package/npm/danfojs) to your HTML file:
7171

7272
```html
73-
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.1/lib/bundle.js"></script>
73+
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.2/lib/bundle.js"></script>
7474
```
7575
See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
7676

@@ -85,7 +85,7 @@ See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
8585
<head>
8686
<meta charset="UTF-8" />
8787
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88-
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.1/lib/bundle.js"></script>
88+
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.2/lib/bundle.js"></script>
8989

9090
<title>Document</title>
9191
</head>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "danfo",
3+
"version": "1.0.2",
34
"private": true,
45
"workspaces": [
56
"danfojs-node/**",

src/danfojs-base/core/datetime.ts

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export default class TimeSeries implements DateTime {
4646
* Returns the month, in local time.
4747
* @example
4848
* ```
49-
* import { Dataframe } from "danfojs-node"
49+
* import { Series } from "danfojs-node"
5050
* const data = [
5151
* "2019-01-01",
5252
* "2019-02-01",
5353
* "2019-03-01",
5454
* "2019-04-01",
5555
* ]
56-
* const df = new Dataframe(data)
56+
* const df = new Series(data)
5757
* const dfNew = df.dt.month()
5858
* console.log(dfNew.values)
5959
* // [1, 2, 3, 4]
@@ -68,19 +68,19 @@ export default class TimeSeries implements DateTime {
6868
* Returns the day of the week, in local time
6969
* @example
7070
* ```
71-
* import { Dataframe } from "danfojs-node"
71+
* import { Series } from "danfojs-node"
7272
* const data = [
7373
* "2019-01-01",
7474
* "2019-02-01",
7575
* "2019-03-01",
7676
* "2019-04-01",
7777
* ]
78-
* const df = new Dataframe(data)
78+
* const df = new Series(data)
7979
* const dayOfWeek = df.dt.dayOfWeek()
8080
* console.log(dayOfWeek.values)
8181
* ```
8282
*/
83-
dayOfWeek() {
83+
dayOfWeek() {
8484
const newValues = this.$dateObjectArray.map(date => date.getDay())
8585
return new Series(newValues);
8686
}
@@ -89,14 +89,14 @@ export default class TimeSeries implements DateTime {
8989
* Returns the year, in local time
9090
* @example
9191
* ```
92-
* import { Dataframe } from "danfojs-node"
92+
* import { Series } from "danfojs-node"
9393
* const data = [
9494
* "2019-01-01",
9595
* "2019-02-01",
9696
* "2021-03-01",
9797
* "2020-04-01",
9898
* ]
99-
* const df = new Dataframe(data)
99+
* const df = new Series(data)
100100
* const year = df.dt.year()
101101
* console.log(year.values)
102102
* // [2019, 2019, 2021, 2020]
@@ -111,14 +111,14 @@ export default class TimeSeries implements DateTime {
111111
* Returns the name of the month, in local time
112112
* @example
113113
* ```
114-
* import { Dataframe } from "danfojs-node"
114+
* import { Series } from "danfojs-node"
115115
* const data = [
116116
* "2019-01-01",
117117
* "2019-02-01",
118118
* "2021-03-01",
119119
* "2020-04-01",
120120
* ]
121-
* const df = new Dataframe(data)
121+
* const df = new Series(data)
122122
* const monthName = df.dt.monthName().values
123123
* console.log(monthName)
124124
* // ["January", "February", "March", "April"]
@@ -133,14 +133,14 @@ export default class TimeSeries implements DateTime {
133133
* Returns the name of the day, of the week, in local time
134134
* @example
135135
* ```
136-
* import { Dataframe } from "danfojs-node"
136+
* import { Series } from "danfojs-node"
137137
* const data = [
138138
* "2019-01-01",
139139
* "2019-02-01",
140140
* "2021-03-01",
141141
* "2020-04-01",
142142
* ]
143-
* const df = new Dataframe(data)
143+
* const df = new Series(data)
144144
* const dayOfWeekName = df.dt.dayOfWeekName().values
145145
* console.log(dayOfWeekName)
146146
* ```
@@ -154,14 +154,14 @@ export default class TimeSeries implements DateTime {
154154
* Returns the day of the month, in local time
155155
* @example
156156
* ```
157-
* import { Dataframe } from "danfojs-node"
157+
* import { Series } from "danfojs-node"
158158
* const data = [
159159
* "2019-01-01",
160160
* "2019-02-05",
161161
* "2021-03-02",
162162
* "2020-04-01",
163163
* ]
164-
* const df = new Dataframe(data)
164+
* const df = new Series(data)
165165
* const dayOfMonth = df.dt.dayOfMonth().values
166166
* console.log(dayOfMonth)
167167
* // [1, 5, 2, 1]
@@ -176,14 +176,14 @@ export default class TimeSeries implements DateTime {
176176
* Returns the hour of the day, in local time
177177
* @example
178178
* ```
179-
* import { Dataframe } from "danfojs-node"
179+
* import { Series } from "danfojs-node"
180180
* const data = [
181181
* "2019-01-01",
182182
* "2019-02-05",
183183
* "2021-03-02",
184184
* "2020-04-01",
185185
* ]
186-
* const df = new Dataframe(data)
186+
* const df = new Series(data)
187187
* const hour = df.dt.hour().values
188188
* console.log(hour)
189189
* // [0, 0, 0, 0]
@@ -198,14 +198,14 @@ export default class TimeSeries implements DateTime {
198198
* Returns the second of the day, in local time
199199
* @example
200200
* ```
201-
* import { Dataframe } from "danfojs-node"
201+
* import { Series } from "danfojs-node"
202202
* const data = [
203203
* "2019-01-01",
204204
* "2019-02-05",
205205
* "2021-03-02",
206206
* "2020-04-01",
207207
* ]
208-
* const df = new Dataframe(data)
208+
* const df = new Series(data)
209209
* const second = df.dt.second().values
210210
* console.log(second)
211211
* ```
@@ -219,14 +219,14 @@ export default class TimeSeries implements DateTime {
219219
* Returns the minute of the day, in local time
220220
* @example
221221
* ```
222-
* import { Dataframe } from "danfojs-node"
222+
* import { Series } from "danfojs-node"
223223
* const data = [
224224
* "2019-01-01",
225225
* "2019-02-05",
226226
* "2021-03-02",
227227
* "2020-04-01",
228228
* ]
229-
* const df = new Dataframe(data)
229+
* const df = new Series(data)
230230
* const minute = df.dt.minute().values
231231
* console.log(minute)
232232
* ```
@@ -236,6 +236,28 @@ export default class TimeSeries implements DateTime {
236236
return new Series(newValues);
237237
}
238238

239+
/**
240+
* Returns the Date as JavaScript standard Date object
241+
* @example
242+
* ```
243+
* import { Series } from "danfojs-node"
244+
* const data = [
245+
* "2019-01-01",
246+
* "2019-02-05",
247+
* "2021-03-02",
248+
* "2020-04-01",
249+
* ]
250+
*
251+
* const df = new Series(data)
252+
* const date = df.dt.toDate().values
253+
* console.log(date)
254+
* ```
255+
*/
256+
date() {
257+
const newValues = this.$dateObjectArray.map(date => date.toLocaleString())
258+
return new Series(newValues);
259+
}
260+
239261
}
240262

241263
export const toDateTime = (data: Series | ArrayType1D) => {

src/danfojs-base/core/frame.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
17471747
options?: { inplace?: boolean, atIndex?: number | string }
17481748
): DataFrame | void {
17491749
let { inplace, atIndex } = { inplace: false, atIndex: this.columns.length, ...options };
1750-
if (typeof atIndex === "string" ) {
1751-
if (!(this.columns.includes(atIndex))){
1750+
if (typeof atIndex === "string") {
1751+
if (!(this.columns.includes(atIndex))) {
17521752
throw new Error(`${atIndex} not a column`)
17531753
}
17541754
atIndex = this.columns.indexOf(atIndex)
@@ -2762,7 +2762,7 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
27622762
inplace?: boolean
27632763
}
27642764
): DataFrame
2765-
rename(
2765+
rename(
27662766
mapper: {
27672767
[index: string | number]: string | number
27682768
},
@@ -3332,4 +3332,47 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
33323332
return toExcelNode(this, options as ExcelOutputOptionsNode)
33333333
}
33343334
}
3335+
3336+
/**
3337+
* Access a single value for a row/column pair by integer position.
3338+
* Similar to {@link iloc}, in that both provide integer-based lookups.
3339+
* Use iat if you only need to get or set a single value in a DataFrame.
3340+
* @param row Row index of the value to access.
3341+
* @param column Column index of the value to access.
3342+
* @example
3343+
* ```
3344+
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3345+
* df.iat(0, 0) // 1
3346+
* df.iat(0, 1) // 2
3347+
* df.iat(1, 0) // 3
3348+
* ```
3349+
*/
3350+
iat(row: number, column: number): string | number | boolean | undefined {
3351+
if (typeof row === 'string' || typeof column === 'string') {
3352+
throw new Error('ParamError: row and column index must be an integer. Use .at to get a row or column by label.')
3353+
}
3354+
3355+
return (this.values as ArrayType2D)[row][column]
3356+
}
3357+
3358+
/**
3359+
* Access a single value for a row/column label pair.
3360+
* Similar to {@link loc}, in that both provide label-based lookups.
3361+
* Use at if you only need to get or set a single value in a DataFrame.
3362+
* @param row Row index of the value to access.
3363+
* @param column Column label of the value to access.
3364+
* @example
3365+
* ```
3366+
* const df = new DataFrame([[1, 2], [3, 4]], { columns: ['A', 'B']})
3367+
* df.at(0,'A') // 1
3368+
* df.at(1, 'A') // 3
3369+
* df.at(1, 'B') // 4
3370+
* ```
3371+
*/
3372+
at(row: string | number, column: string): string | number | boolean | undefined {
3373+
if (typeof column !== 'string') {
3374+
throw new Error('ParamError: column index must be a string. Use .iat to get a row or column by index.')
3375+
}
3376+
return (this.values as ArrayType2D)[this.index.indexOf(row)][this.columns.indexOf(column)]
3377+
}
33353378
}

src/danfojs-base/core/series.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,10 @@ export default class Series extends NDframe implements SeriesInterface {
674674
* //output [ 1.23, 2.4, 3.12, 4.12, 5.12 ]
675675
* ```
676676
*/
677+
round(dp?: number, options?: { inplace?: boolean }): Series
677678
round(dp = 1, options?: { inplace?: boolean }): Series | void {
678679
const { inplace } = { inplace: false, ...options }
679-
680+
if (dp === undefined) dp = 1;
680681
const newValues = utils.round(this.values as number[], dp, true);
681682

682683
if (inplace) {
@@ -816,24 +817,26 @@ export default class Series extends NDframe implements SeriesInterface {
816817
const { ascending, inplace, } = { ascending: true, inplace: false, ...options }
817818

818819
let sortedValues = [];
820+
let sortedIndex = []
819821
const rangeIdx = utils.range(0, this.index.length - 1);
820822
let sortedIdx = utils.sortArrayByIndex(rangeIdx, this.values, this.dtypes[0]);
821823

822824
for (let indx of sortedIdx) {
823825
sortedValues.push(this.values[indx])
826+
sortedIndex.push(this.index[indx])
824827
}
825828

826829
if (ascending) {
827830
sortedValues = sortedValues.reverse();
828-
sortedIdx = sortedIdx.reverse();
831+
sortedIndex = sortedIndex.reverse();
829832
}
830833

831834
if (inplace) {
832835
this.$setValues(sortedValues as ArrayType1D)
833-
this.$setIndex(sortedIdx);
836+
this.$setIndex(sortedIndex);
834837
} else {
835838
const sf = new Series(sortedValues, {
836-
index: sortedIdx,
839+
index: sortedIndex,
837840
dtypes: this.dtypes,
838841
config: this.config
839842
});
@@ -1828,6 +1831,11 @@ export default class Series extends NDframe implements SeriesInterface {
18281831
* //output [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
18291832
* ```
18301833
*/
1834+
append(
1835+
newValue: string | number | boolean | Series | ArrayType1D,
1836+
index: Array<number | string> | number | string,
1837+
options?: { inplace?: boolean }
1838+
): Series
18311839
append(
18321840
newValue: string | number | boolean | Series | ArrayType1D,
18331841
index: Array<number | string> | number | string,
@@ -2239,4 +2247,44 @@ export default class Series extends NDframe implements SeriesInterface {
22392247
return toExcelNode(this, options as ExcelOutputOptionsNode)
22402248
}
22412249
}
2250+
2251+
/**
2252+
* Access a single value for a row index.
2253+
* Similar to iloc, in that both provide index-based lookups.
2254+
* Use iat if you only need to get or set a single value in a Series.
2255+
* @param row Row index of the value to access.
2256+
* @example
2257+
* ```
2258+
* const sf = new Series([1, 2, 3, 4, 5])
2259+
* sf.iat(0) //returns 1
2260+
* sf.iat(1) //returns 2
2261+
* sf.iat(2) //returns 3
2262+
* ```
2263+
*/
2264+
iat(row: number): number | string | boolean | undefined {
2265+
if (typeof row === 'string') {
2266+
throw new Error('ParamError: row index must be an integer. Use .at to get a row by label.')
2267+
}
2268+
return (this.values as ArrayType1D)[row];
2269+
}
2270+
2271+
/**
2272+
* Access a single value for a row label.
2273+
* Similar to loc, in that both provide label-based lookups.
2274+
* Use at if you only need to get or set a single value in a Series.
2275+
* @param row Row label of the value to access.
2276+
* @example
2277+
* ```
2278+
* const sf = new Series([1, 2, 3, 4, 5, 6], { index: ['A', 'B', 'C', 'D', 'E', 'F'] })
2279+
* sf.at('A') //returns 1
2280+
* sf.at('B') //returns 2
2281+
* sf.at('C') //returns 3
2282+
* ```
2283+
*/
2284+
at(row: string): number | string | boolean | undefined {
2285+
if (typeof row !== 'string') {
2286+
throw new Error('ParamError: row index must be a string. Use .iat to get a row by index.')
2287+
}
2288+
return (this.values as ArrayType1D)[this.index.indexOf(row)];
2289+
}
22422290
}

src/danfojs-base/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import merge from "./transformers/merge"
2929
import dateRange from "./core/daterange"
3030
import tensorflow from "./shared/tensorflowlib"
3131

32-
const __version = "1.0.1";
32+
const __version = "1.0.2";
3333

3434
export {
3535
NDframe,

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.