node-pandas 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.kiro/agents/git-committer-agent.md +208 -0
- package/.kiro/agents/npm-publisher-agent.md +501 -0
- package/.kiro/publish-status-2.0.0.md +134 -0
- package/.kiro/published-versions.md +11 -0
- package/.kiro/specs/pandas-like-enhancements/.config.kiro +1 -0
- package/.kiro/specs/pandas-like-enhancements/design.md +377 -0
- package/.kiro/specs/pandas-like-enhancements/requirements.md +257 -0
- package/.kiro/specs/pandas-like-enhancements/tasks.md +477 -0
- package/CHANGELOG.md +42 -0
- package/README.md +375 -103
- package/TESTING_SETUP.md +183 -0
- package/jest.config.js +25 -0
- package/package.json +11 -3
- package/src/bases/CsvBase.js +4 -13
- package/src/dataframe/dataframe.js +596 -64
- package/src/features/GroupBy.js +561 -0
- package/src/features/dateRange.js +106 -0
- package/src/index.js +6 -1
- package/src/series/series.js +690 -14
- package/src/utils/errors.js +314 -0
- package/src/utils/getIndicesColumns.js +1 -1
- package/src/utils/getTransformedDataList.js +1 -1
- package/src/utils/logger.js +259 -0
- package/src/utils/typeDetection.js +339 -0
- package/src/utils/utils.js +5 -1
- package/src/utils/validation.js +450 -0
- package/tests/README.md +151 -0
- package/tests/integration/.gitkeep +0 -0
- package/tests/integration/README.md +3 -0
- package/tests/property/.gitkeep +0 -0
- package/tests/property/README.md +3 -0
- package/tests/setup.js +16 -0
- package/tests/test.js +58 -21
- package/tests/unit/.gitkeep +0 -0
- package/tests/unit/README.md +3 -0
- package/tests/unit/dataframe.test.js +1141 -0
- package/tests/unit/example.test.js +23 -0
- package/tests/unit/series.test.js +441 -0
- package/tests/unit/tocsv.test.js +838 -0
- package/tests/utils/testAssertions.js +143 -0
- package/tests/utils/testDataGenerator.js +123 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom assertion utilities for testing
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Assert that two arrays are deeply equal
|
|
7
|
+
* @param {any[]} actual - Actual array
|
|
8
|
+
* @param {any[]} expected - Expected array
|
|
9
|
+
* @param {string} message - Error message
|
|
10
|
+
*/
|
|
11
|
+
function assertArrayEqual(actual, expected, message = '') {
|
|
12
|
+
if (!Array.isArray(actual) || !Array.isArray(expected)) {
|
|
13
|
+
throw new Error(`${message} - Both values must be arrays`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (actual.length !== expected.length) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`${message} - Array length mismatch: expected ${expected.length}, got ${actual.length}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < actual.length; i++) {
|
|
23
|
+
if (actual[i] !== expected[i]) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${message} - Array element mismatch at index ${i}: expected ${expected[i]}, got ${actual[i]}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Assert that a value is numeric
|
|
33
|
+
* @param {any} value - Value to check
|
|
34
|
+
* @param {string} message - Error message
|
|
35
|
+
*/
|
|
36
|
+
function assertNumeric(value, message = '') {
|
|
37
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
38
|
+
throw new Error(`${message} - Expected numeric value, got ${typeof value}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Assert that a value is a string
|
|
44
|
+
* @param {any} value - Value to check
|
|
45
|
+
* @param {string} message - Error message
|
|
46
|
+
*/
|
|
47
|
+
function assertString(value, message = '') {
|
|
48
|
+
if (typeof value !== 'string') {
|
|
49
|
+
throw new Error(`${message} - Expected string, got ${typeof value}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Assert that a value is null or undefined
|
|
55
|
+
* @param {any} value - Value to check
|
|
56
|
+
* @param {string} message - Error message
|
|
57
|
+
*/
|
|
58
|
+
function assertNullish(value, message = '') {
|
|
59
|
+
if (value !== null && value !== undefined) {
|
|
60
|
+
throw new Error(`${message} - Expected null or undefined, got ${value}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Assert that two numeric values are approximately equal
|
|
66
|
+
* @param {number} actual - Actual value
|
|
67
|
+
* @param {number} expected - Expected value
|
|
68
|
+
* @param {number} tolerance - Tolerance for comparison
|
|
69
|
+
* @param {string} message - Error message
|
|
70
|
+
*/
|
|
71
|
+
function assertApproximatelyEqual(actual, expected, tolerance = 0.0001, message = '') {
|
|
72
|
+
if (Math.abs(actual - expected) > tolerance) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`${message} - Values not approximately equal: expected ${expected}, got ${actual} (tolerance: ${tolerance})`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Assert that a value is an instance of a class
|
|
81
|
+
* @param {any} value - Value to check
|
|
82
|
+
* @param {Function} constructor - Constructor function
|
|
83
|
+
* @param {string} message - Error message
|
|
84
|
+
*/
|
|
85
|
+
function assertInstanceOf(value, constructor, message = '') {
|
|
86
|
+
if (!(value instanceof constructor)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`${message} - Expected instance of ${constructor.name}, got ${typeof value}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Assert that an object has specific properties
|
|
95
|
+
* @param {Object} obj - Object to check
|
|
96
|
+
* @param {string[]} properties - Property names to check
|
|
97
|
+
* @param {string} message - Error message
|
|
98
|
+
*/
|
|
99
|
+
function assertHasProperties(obj, properties, message = '') {
|
|
100
|
+
for (const prop of properties) {
|
|
101
|
+
if (!(prop in obj)) {
|
|
102
|
+
throw new Error(`${message} - Object missing property: ${prop}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Assert that a 2D array has specific dimensions
|
|
109
|
+
* @param {any[][]} array - 2D array to check
|
|
110
|
+
* @param {number} expectedRows - Expected number of rows
|
|
111
|
+
* @param {number} expectedCols - Expected number of columns
|
|
112
|
+
* @param {string} message - Error message
|
|
113
|
+
*/
|
|
114
|
+
function assert2DArrayDimensions(array, expectedRows, expectedCols, message = '') {
|
|
115
|
+
if (!Array.isArray(array)) {
|
|
116
|
+
throw new Error(`${message} - Expected array, got ${typeof array}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (array.length !== expectedRows) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`${message} - Row count mismatch: expected ${expectedRows}, got ${array.length}`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (let i = 0; i < array.length; i++) {
|
|
126
|
+
if (!Array.isArray(array[i]) || array[i].length !== expectedCols) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`${message} - Column count mismatch at row ${i}: expected ${expectedCols}, got ${array[i]?.length || 'not an array'}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = {
|
|
135
|
+
assertArrayEqual,
|
|
136
|
+
assertNumeric,
|
|
137
|
+
assertString,
|
|
138
|
+
assertNullish,
|
|
139
|
+
assertApproximatelyEqual,
|
|
140
|
+
assertInstanceOf,
|
|
141
|
+
assertHasProperties,
|
|
142
|
+
assert2DArrayDimensions
|
|
143
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test data generator utilities for creating sample data for tests
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate a simple numeric array
|
|
7
|
+
* @param {number} length - Length of array
|
|
8
|
+
* @param {number} start - Starting value
|
|
9
|
+
* @returns {number[]} Array of numbers
|
|
10
|
+
*/
|
|
11
|
+
function generateNumericArray(length = 10, start = 1) {
|
|
12
|
+
return Array.from({ length }, (_, i) => start + i);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generate a numeric array with mixed types
|
|
17
|
+
* @param {number} length - Length of array
|
|
18
|
+
* @returns {(number|string|null)[]} Array with mixed types
|
|
19
|
+
*/
|
|
20
|
+
function generateMixedArray(length = 10) {
|
|
21
|
+
const result = [];
|
|
22
|
+
for (let i = 0; i < length; i++) {
|
|
23
|
+
const type = i % 3;
|
|
24
|
+
if (type === 0) result.push(i);
|
|
25
|
+
else if (type === 1) result.push(`value_${i}`);
|
|
26
|
+
else result.push(null);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generate a 2D array for DataFrame
|
|
33
|
+
* @param {number} rows - Number of rows
|
|
34
|
+
* @param {number} cols - Number of columns
|
|
35
|
+
* @returns {number[][]} 2D array
|
|
36
|
+
*/
|
|
37
|
+
function generate2DArray(rows = 5, cols = 3) {
|
|
38
|
+
return Array.from({ length: rows }, (_, i) =>
|
|
39
|
+
Array.from({ length: cols }, (_, j) => i * cols + j)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate sample DataFrame data with column names
|
|
45
|
+
* @param {number} rows - Number of rows
|
|
46
|
+
* @returns {Object} Object with data and columns
|
|
47
|
+
*/
|
|
48
|
+
function generateDataFrameData(rows = 5) {
|
|
49
|
+
const data = Array.from({ length: rows }, (_, i) => [
|
|
50
|
+
i + 1,
|
|
51
|
+
`name_${i}`,
|
|
52
|
+
Math.random() * 100
|
|
53
|
+
]);
|
|
54
|
+
const columns = ['id', 'name', 'value'];
|
|
55
|
+
return { data, columns };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Generate sample data with categories for grouping
|
|
60
|
+
* @param {number} rows - Number of rows
|
|
61
|
+
* @returns {Object} Object with data and columns
|
|
62
|
+
*/
|
|
63
|
+
function generateCategoricalData(rows = 12) {
|
|
64
|
+
const categories = ['A', 'B', 'C'];
|
|
65
|
+
const data = Array.from({ length: rows }, (_, i) => [
|
|
66
|
+
categories[i % 3],
|
|
67
|
+
Math.floor(Math.random() * 100),
|
|
68
|
+
Math.random() * 50
|
|
69
|
+
]);
|
|
70
|
+
const columns = ['category', 'count', 'value'];
|
|
71
|
+
return { data, columns };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Generate sample data with null values
|
|
76
|
+
* @param {number} rows - Number of rows
|
|
77
|
+
* @returns {Object} Object with data and columns
|
|
78
|
+
*/
|
|
79
|
+
function generateDataWithNulls(rows = 5) {
|
|
80
|
+
const data = Array.from({ length: rows }, (_, i) => [
|
|
81
|
+
i + 1,
|
|
82
|
+
i % 2 === 0 ? `name_${i}` : null,
|
|
83
|
+
i % 3 === 0 ? null : Math.random() * 100
|
|
84
|
+
]);
|
|
85
|
+
const columns = ['id', 'name', 'value'];
|
|
86
|
+
return { data, columns };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generate sample data for merging
|
|
91
|
+
* @returns {Object} Object with two datasets for merging
|
|
92
|
+
*/
|
|
93
|
+
function generateMergeData() {
|
|
94
|
+
const left = {
|
|
95
|
+
data: [
|
|
96
|
+
[1, 'Alice'],
|
|
97
|
+
[2, 'Bob'],
|
|
98
|
+
[3, 'Charlie']
|
|
99
|
+
],
|
|
100
|
+
columns: ['id', 'name']
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const right = {
|
|
104
|
+
data: [
|
|
105
|
+
[1, 100],
|
|
106
|
+
[2, 200],
|
|
107
|
+
[3, 300]
|
|
108
|
+
],
|
|
109
|
+
columns: ['id', 'score']
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return { left, right };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
generateNumericArray,
|
|
117
|
+
generateMixedArray,
|
|
118
|
+
generate2DArray,
|
|
119
|
+
generateDataFrameData,
|
|
120
|
+
generateCategoricalData,
|
|
121
|
+
generateDataWithNulls,
|
|
122
|
+
generateMergeData
|
|
123
|
+
};
|