Skip to content

Commit 6a95f1f

Browse files
committed
2 parents c938fb8 + 0058473 commit 6a95f1f

11 files changed

Lines changed: 340 additions & 174 deletions

File tree

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
patreon: danfojs

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at danfojs@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
## danfojs: powerful javascript data analysis toolkit
99
![Node.js CI](https://github.com/opensource9ja/danfojs/workflows/Node.js%20CI/badge.svg?branch=master)
1010
[![](https://data.jsdelivr.com/v1/package/npm/danfojs/badge?style=rounded)](https://www.jsdelivr.com/package/npm/danfojs)
11-
11+
[![Build Status](https://travis-ci.org/opensource9ja/danfojs.svg?branch=master)](https://travis-ci.org/opensource9ja/danfojs)
12+
![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2FDanfoJs)
1213

1314

1415
## What is it?

danfojs/src/core/frame.js

Lines changed: 30 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ export class DataFrame extends Ndframe {
776776
let col_names = numeric_df.column_names
777777
let index = ['count', 'mean', 'std', 'min', 'median', 'max', 'variance']
778778

779-
let stats_arr = []
779+
let stats_arr = {}
780780
col_names.forEach(name => {
781781
let col_series = numeric_df[name]
782782
let count = col_series.count()
@@ -788,9 +788,7 @@ export class DataFrame extends Ndframe {
788788
let variance = col_series.var()
789789

790790
let _stats = [count, mean, std, min, median, max, variance]
791-
let col_obj = {}
792-
col_obj[name] = _stats
793-
stats_arr.push(col_obj)
791+
stats_arr[name] = _stats
794792

795793
})
796794
let df = new DataFrame(stats_arr, { "index": index })
@@ -803,42 +801,36 @@ export class DataFrame extends Ndframe {
803801
* @param {include} scalar or array-like. A selection of dtypes or strings to be included. At least one of these parameters must be supplied.
804802
* @returns {DataFrame, Series} The subset of the frame including the dtypes.
805803
*/
806-
select_dtypes(include = [""]) {
804+
select_dtypes(include) {
807805
let dtypes = this.dtypes
808-
// let dtype_index = [...Array(this.dtypes.length - 1).keys()]
809-
let col_vals = []
806+
let col_names = this.column_names
807+
let col_vals = {}
810808
let original_col_vals = this.col_data
811-
const __supported_dtypes = ['float32', "int32", 'string', 'datetime']
809+
const __supported_dtypes = ['float32', "int32", 'string', 'boolean']
812810

813-
if (include == [""] || include == []) {
811+
if (include == undefined) {
814812
//return all
815813
let df = this.copy()
816814
return df
817815
} else {
818816
//check if the right types are included
819817
include.forEach(type => {
820818
if (!__supported_dtypes.includes(type)) {
821-
throw Error(`Dtype Error: dtype ${type} not found in dtypes`)
819+
throw Error(`Dtype Error: dtype ${type} not supported.`)
822820
}
823-
dtypes.map((dtype, i) => {
824-
if (dtype == type) {
825-
let _obj = {}
826-
_obj[this.column_names[i]] = original_col_vals[i]
827-
col_vals.push(_obj)
828-
}
829-
})
821+
})
822+
823+
824+
dtypes.forEach((dtype, i) => {
825+
if (include.includes(dtype)) {
826+
console.log(dtype);
827+
col_vals[col_names[i]] = original_col_vals[i]
828+
}
829+
})
830+
let df = new DataFrame(col_vals)
831+
df.print()
832+
return df
830833

831-
});
832-
if (col_vals.length == 1) {
833-
let _key = Object.keys(col_vals[0])[0]
834-
let data = col_vals[0][_key]
835-
let column_name = [_key]
836-
let sf = new Series(data, { columns: column_name, index: this.index })
837-
return sf
838-
} else {
839-
let df = new DataFrame(col_vals, { index: this.index })
840-
return df
841-
}
842834
}
843835

844836
}
@@ -1209,6 +1201,7 @@ export class DataFrame extends Ndframe {
12091201
}
12101202
})
12111203

1204+
12121205
if (kwargs['columns'].length != kwargs['values'].length) {
12131206
throw Error(`Lenght Error: The lenght of the columns names must be equal to the lenght of the values,
12141207
got column of length ${kwargs['columns'].length} but values of length ${kwargs['values'].length}`)
@@ -1231,38 +1224,11 @@ export class DataFrame extends Ndframe {
12311224

12321225
})
12331226

1234-
let final_data = []
1227+
let final_data = {}
12351228
new_col_data.map((col, i) => {
1236-
let col_obj = {}
1237-
col_obj[this.column_names[i]] = col
1238-
final_data.push(col_obj)
1229+
final_data[this.column_names[i]] = col
12391230
})
1240-
// let fil_idx = 0
1241-
// this.column_names.map((col, idx) => {
1242-
// let _obj = {}
1243-
// if (kwargs['columns'].includes(col)) {
1244-
// console.log(fil_idx);
1245-
// console.log(col);
1246-
// console.log(kwargs['values'][fil_idx]);
1247-
// let temp_col_data = this.col_data[idx] //retreive the column data
1248-
// let __temp = []
1249-
// temp_col_data.map(val => { //fill the column
1250-
// if (isNaN(val) && typeof val != "string") {
1251-
// __temp.push(kwargs['values'][fil_idx])
1252-
1253-
// } else {
1254-
// __temp.push(val)
1255-
// }
1256-
// })
1257-
// fil_idx += 1
1258-
// _obj[col] = __temp
1259-
// new_col_data_obj.push(_obj)
1260-
// } else {
1261-
// _obj[col] = this.col_data[idx]
1262-
// new_col_data_obj.push(_obj)
1263-
// }
1264-
1265-
// })
1231+
12661232
return new DataFrame(final_data, { index: this.index })
12671233

12681234
} else {
@@ -1663,9 +1629,8 @@ export class DataFrame extends Ndframe {
16631629
})
16641630

16651631
if (utils.__key_in_object(kwargs, "replace") && utils.__key_in_object(kwargs, "with")) {
1666-
let new_col_data_obj = []
1632+
let new_col_data_obj = {}
16671633
this.column_names.map((col, idx) => {
1668-
let _obj = {}
16691634
if (kwargs['in'].includes(col)) {
16701635
let temp_col_data = this.col_data[idx] //retreive the column data
16711636
let __temp = []
@@ -1676,11 +1641,9 @@ export class DataFrame extends Ndframe {
16761641
__temp.push(val)
16771642
}
16781643
})
1679-
_obj[col] = __temp
1680-
new_col_data_obj.push(_obj)
1644+
new_col_data_obj[col] = __temp
16811645
} else {
1682-
_obj[col] = this.col_data[idx]
1683-
new_col_data_obj.push(_obj)
1646+
new_col_data_obj[col] = this.col_data[idx]
16841647
}
16851648
})
16861649
return new DataFrame(new_col_data_obj, { columns: this.column_names, index: this.index })
@@ -1900,7 +1863,7 @@ export class DataFrame extends Ndframe {
19001863
return plt
19011864
}
19021865

1903-
1866+
19041867

19051868
/**
19061869
* Returns the Tensorflow tensor backing the DataFrame Object
@@ -1963,11 +1926,9 @@ export class DataFrame extends Ndframe {
19631926
break;
19641927
}
19651928

1966-
let new_col_obj = []
1929+
let new_col_obj = {}
19671930
this.column_names.forEach((cname, i) => {
1968-
let _obj = {}
1969-
_obj[cname] = col_values[i]
1970-
new_col_obj.push(_obj)
1931+
new_col_obj[cname] = col_values[i]
19711932
})
19721933

19731934
let df = new DataFrame(new_col_obj, { dtypes: new_types, index: this.index })

danfojs/src/core/generic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export default class NDframe {
3333
this.series = false
3434
if (utils.__is_object(data[0])) { //check the type of the first object in the data
3535
this.__read_object(data, 1) //type 1 object are of JSON form [{a: 1, b: 2}, {a: 30, b: 20}]
36-
} else if (Array.isArray(data[0]) || utils.__is_number(data[0]) || utils.__is_string(data[0])) {
37-
this.__read_array(data)
3836
} else if (utils.__is_object(data)) {
3937
this.__read_object(data, 2) //type 2 object are of the form {a: [1,2,3,4], b: [30,20, 30, 20}]
38+
} else if (Array.isArray(data[0]) || utils.__is_number(data[0]) || utils.__is_string(data[0])) {
39+
this.__read_array(data)
4040
} else {
4141
throw "File format not supported for now"
4242
}
@@ -165,7 +165,7 @@ export default class NDframe {
165165
__set_col_types(dtypes, infer) {
166166
//set data type for each column in an NDFrame
167167
const __supported_dtypes = ['float32', "int32", 'string', 'boolean']
168-
168+
169169

170170
if (infer) {
171171
if (this.series) {
@@ -178,7 +178,7 @@ export default class NDframe {
178178
this.col_types = utils.__get_t(this.col_data)
179179
}
180180
} else {
181-
181+
182182
if (this.series) {
183183
this.col_types = dtypes
184184
this.col_data = [this.values]

0 commit comments

Comments
 (0)