evalsense 0.3.0 → 0.3.2

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getCurrentSuite, setCurrentSuite, addSuite, addTestToCurrentSuite, DatasetError, IntegrityError, buildConfusionMatrix, getTruePositives, getFalsePositives, getFalseNegatives, getSupport, AssertionError, recordAssertion, recordFieldMetrics } from './chunk-JPVZL45G.js';
2
- export { AssertionError, ConfigurationError, ConsoleReporter, DatasetError, EvalSenseError, ExitCodes, IntegrityError, JsonReporter, TestExecutionError, buildConfusionMatrix, discoverEvalFiles, executeEvalFiles, formatConfusionMatrix, getExitCode, parseReport } from './chunk-JPVZL45G.js';
1
+ import { getCurrentSuite, setCurrentSuite, addSuite, addTestToCurrentSuite, DatasetError, IntegrityError, buildConfusionMatrix, getTruePositives, getFalsePositives, getFalseNegatives, getSupport, AssertionError, recordAssertion, recordFieldMetrics } from './chunk-IYLSY7NX.js';
2
+ export { AssertionError, ConfigurationError, ConsoleReporter, DatasetError, EvalSenseError, ExitCodes, IntegrityError, JsonReporter, TestExecutionError, buildConfusionMatrix, discoverEvalFiles, executeEvalFiles, formatConfusionMatrix, getExitCode, parseReport } from './chunk-IYLSY7NX.js';
3
3
  import './chunk-DGUM43GV.js';
4
4
  import { readFileSync } from 'fs';
5
5
  import { resolve, extname } from 'path';
@@ -224,16 +224,28 @@ async function runModelParallel(dataset, modelFn, concurrency = 10) {
224
224
 
225
225
  // src/dataset/alignment.ts
226
226
  function alignByKey(predictions, expected, options = {}) {
227
- const { strict = false, idField = "id" } = options;
227
+ const { strict = false, idField, predictionIdField, expectedIdField } = options;
228
+ const predIdField = predictionIdField ?? idField ?? "id";
229
+ const expIdField = expectedIdField ?? idField ?? "id";
228
230
  const expectedMap = /* @__PURE__ */ new Map();
229
231
  for (const record of expected) {
230
- const id = String(record[idField] ?? record._id);
232
+ const id = String(record[expIdField] ?? record._id);
233
+ if (!id || id === "undefined") {
234
+ throw new IntegrityError(
235
+ `Expected record missing ${expIdField} field: ${JSON.stringify(record)}`
236
+ );
237
+ }
231
238
  expectedMap.set(id, record);
232
239
  }
233
240
  const aligned = [];
234
241
  const missingIds = [];
235
242
  for (const prediction of predictions) {
236
- const id = prediction.id;
243
+ const id = String(prediction[predIdField]);
244
+ if (!id || id === "undefined") {
245
+ throw new IntegrityError(
246
+ `Prediction missing ${predIdField} field: ${JSON.stringify(prediction)}`
247
+ );
248
+ }
237
249
  const expectedRecord = expectedMap.get(id);
238
250
  if (!expectedRecord) {
239
251
  missingIds.push(id);
@@ -555,9 +567,6 @@ var BinarizeSelector = class {
555
567
  };
556
568
  this.assertions.push(result);
557
569
  recordAssertion(result);
558
- if (!passed) {
559
- throw new AssertionError(result.message, threshold, metrics.accuracy, this.fieldName);
560
- }
561
570
  return this;
562
571
  }
563
572
  /**
@@ -599,9 +608,6 @@ var BinarizeSelector = class {
599
608
  };
600
609
  this.assertions.push(result);
601
610
  recordAssertion(result);
602
- if (!passed) {
603
- throw new AssertionError(result.message, actualThreshold, actualPrecision, this.fieldName);
604
- }
605
611
  return this;
606
612
  }
607
613
  /**
@@ -643,9 +649,6 @@ var BinarizeSelector = class {
643
649
  };
644
650
  this.assertions.push(result);
645
651
  recordAssertion(result);
646
- if (!passed) {
647
- throw new AssertionError(result.message, actualThreshold, actualRecall, this.fieldName);
648
- }
649
652
  return this;
650
653
  }
651
654
  /**
@@ -685,9 +688,6 @@ var BinarizeSelector = class {
685
688
  };
686
689
  this.assertions.push(result);
687
690
  recordAssertion(result);
688
- if (!passed) {
689
- throw new AssertionError(result.message, actualThreshold, actualF1, this.fieldName);
690
- }
691
691
  return this;
692
692
  }
693
693
  /**
@@ -778,9 +778,6 @@ var FieldSelector = class {
778
778
  };
779
779
  this.assertions.push(result);
780
780
  recordAssertion(result);
781
- if (!passed) {
782
- throw new AssertionError(result.message, threshold, metrics.accuracy, this.fieldName);
783
- }
784
781
  return this;
785
782
  }
786
783
  /**
@@ -823,9 +820,6 @@ var FieldSelector = class {
823
820
  };
824
821
  this.assertions.push(result);
825
822
  recordAssertion(result);
826
- if (!passed) {
827
- throw new AssertionError(result.message, actualThreshold, actualPrecision, this.fieldName);
828
- }
829
823
  return this;
830
824
  }
831
825
  /**
@@ -868,9 +862,6 @@ var FieldSelector = class {
868
862
  };
869
863
  this.assertions.push(result);
870
864
  recordAssertion(result);
871
- if (!passed) {
872
- throw new AssertionError(result.message, actualThreshold, actualRecall, this.fieldName);
873
- }
874
865
  return this;
875
866
  }
876
867
  /**
@@ -913,9 +904,6 @@ var FieldSelector = class {
913
904
  };
914
905
  this.assertions.push(result);
915
906
  recordAssertion(result);
916
- if (!passed) {
917
- throw new AssertionError(result.message, actualThreshold, actualF1, this.fieldName);
918
- }
919
907
  return this;
920
908
  }
921
909
  /**
@@ -975,14 +963,6 @@ var FieldSelector = class {
975
963
  };
976
964
  this.assertions.push(result);
977
965
  recordAssertion(result);
978
- if (!passed) {
979
- throw new AssertionError(
980
- result.message,
981
- percentageThreshold,
982
- actualPercentage,
983
- this.fieldName
984
- );
985
- }
986
966
  return this;
987
967
  }
988
968
  /**
@@ -1021,14 +1001,6 @@ var FieldSelector = class {
1021
1001
  };
1022
1002
  this.assertions.push(result);
1023
1003
  recordAssertion(result);
1024
- if (!passed) {
1025
- throw new AssertionError(
1026
- result.message,
1027
- percentageThreshold,
1028
- actualPercentage,
1029
- this.fieldName
1030
- );
1031
- }
1032
1004
  return this;
1033
1005
  }
1034
1006
  // ============================================================================
@@ -1094,9 +1066,6 @@ var FieldSelector = class {
1094
1066
  };
1095
1067
  this.assertions.push(result);
1096
1068
  recordAssertion(result);
1097
- if (!passed) {
1098
- throw new AssertionError(result.message, threshold, metrics.mae, this.fieldName);
1099
- }
1100
1069
  return this;
1101
1070
  }
1102
1071
  /**
@@ -1125,9 +1094,6 @@ var FieldSelector = class {
1125
1094
  };
1126
1095
  this.assertions.push(result);
1127
1096
  recordAssertion(result);
1128
- if (!passed) {
1129
- throw new AssertionError(result.message, threshold, metrics.rmse, this.fieldName);
1130
- }
1131
1097
  return this;
1132
1098
  }
1133
1099
  /**
@@ -1158,9 +1124,6 @@ var FieldSelector = class {
1158
1124
  };
1159
1125
  this.assertions.push(result);
1160
1126
  recordAssertion(result);
1161
- if (!passed) {
1162
- throw new AssertionError(result.message, threshold, metrics.r2, this.fieldName);
1163
- }
1164
1127
  return this;
1165
1128
  }
1166
1129
  /**
@@ -1205,7 +1168,12 @@ function expectStats(inputOrActual, expected, options) {
1205
1168
  if (!Array.isArray(inputOrActual)) {
1206
1169
  throw new Error("When using two-argument expectStats(), first argument must be Prediction[]");
1207
1170
  }
1208
- const alignOptions = options ? { idField: options.idField, strict: options.strict } : void 0;
1171
+ const alignOptions = options ? {
1172
+ idField: options.idField,
1173
+ predictionIdField: options.predictionIdField,
1174
+ expectedIdField: options.expectedIdField,
1175
+ strict: options.strict
1176
+ } : void 0;
1209
1177
  const aligned2 = alignByKey(inputOrActual, expected, alignOptions);
1210
1178
  return new ExpectStats(aligned2);
1211
1179
  }