| 51 | * @returns NDframe |
| 52 | */ |
| 53 | export default class NDframe implements NDframeInterface { |
| 54 | $isSeries: boolean; |
| 55 | protected $data: any |
| 56 | protected $dataIncolumnFormat: ArrayType1D | ArrayType2D = [] |
| 57 | protected $index: Array<string | number> = [] |
| 58 | protected $columns: string[] = [] |
| 59 | protected $dtypes: Array<string> = [] |
| 60 | protected $config: Configs |
| 61 | |
| 62 | constructor({ data, index, columns, dtypes, config, isSeries }: NdframeInputDataType) { |
| 63 | this.$isSeries = isSeries |
| 64 | if (config) { |
| 65 | this.$config = new Configs({ ...BASE_CONFIG, ...config }); |
| 66 | } else { |
| 67 | this.$config = new Configs(BASE_CONFIG); |
| 68 | } |
| 69 | |
| 70 | if (data instanceof tensorflow.Tensor) { |
| 71 | data = data.arraySync(); |
| 72 | } |
| 73 | |
| 74 | if (data === undefined || (Array.isArray(data) && data.length === 0)) { |
| 75 | if (columns === undefined) columns = []; |
| 76 | if (dtypes === undefined) dtypes = []; |
| 77 | if (columns.length === 0 && dtypes.length !== 0) ErrorThrower.throwDtypeWithoutColumnError(); |
| 78 | this.loadArrayIntoNdframe({ data: [], index: [], columns: columns, dtypes: dtypes }); |
| 79 | } else if (utils.is1DArray(data)) { |
| 80 | this.loadArrayIntoNdframe({ data, index, columns, dtypes }); |
| 81 | } else { |
| 82 | if (Array.isArray(data) && utils.isObject(data[0])) { |
| 83 | this.loadObjectIntoNdframe({ data, type: 1, index, columns, dtypes }); |
| 84 | |
| 85 | } else if (utils.isObject(data)) { |
| 86 | this.loadObjectIntoNdframe({ data, type: 2, index, columns, dtypes }); |
| 87 | |
| 88 | } else if ( |
| 89 | Array.isArray((data)[0]) || |
| 90 | utils.isNumber((data)[0]) || |
| 91 | utils.isString((data)[0]) |
| 92 | ) { |
| 93 | this.loadArrayIntoNdframe({ data, index, columns, dtypes }); |
| 94 | } else if (Array.isArray(data) && data.length > 0 && utils.isDate(data[0])) { |
| 95 | this.loadArrayIntoNdframe({ data, index, columns, dtypes }); |
| 96 | } else { |
| 97 | throw new Error("File format not supported!"); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Internal function to load array of data into NDFrame |
| 104 | * @param data The array of data to load into NDFrame |
| 105 | * @param index Array of numeric or string names for subsetting array. |
| 106 | * @param columns Array of column names. |
| 107 | * @param dtypes Array of data types for each the column. |
| 108 | */ |
| 109 | private loadArrayIntoNdframe({ data, index, columns, dtypes }: LoadArrayDataType): void { |
| 110 | // this.$data = utils.replaceUndefinedWithNaN(data, this.$isSeries); |
nothing calls this directly
no outgoing calls
no test coverage detected