Skip to content

Commit f25f128

Browse files
[Bug] Fix boolean parsing for yes/no string values (#3346) (#3365)
When loading GeoJSON data containing boolean fields with "yes"/"no" string values, type-analyzer correctly classifies the field as boolean, but the kepler.gl parse function only recognized "true"/"True"/"TRUE"/"1" as truthy. This caused all "yes" values to be incorrectly parsed as false. Align the boolean parse function with type-analyzer's boolean recognition by using case-insensitive comparison via String.toLowerCase(). The parser now correctly handles "yes"/"Yes"/"YES" as true and "no"/"No"/"NO" as false, matching the BOOLEAN_TRUE_VALUES and BOOLEAN_FALSE_VALUES defined in type-analyzer. Also expand boolean test coverage to include yes/no variants and additional case combinations (TRUE, false, FALSE). Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
1 parent be6ba64 commit f25f128

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/processors/src/data-processor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ function tryParseJsonString(str) {
5151
export const PARSE_FIELD_VALUE_FROM_STRING = {
5252
[ALL_FIELD_TYPES.boolean]: {
5353
valid: (d: unknown): boolean => typeof d === 'boolean',
54-
parse: (d: unknown): boolean => d === 'true' || d === 'True' || d === 'TRUE' || d === '1'
54+
parse: (d: unknown): boolean => {
55+
const s = String(d).toLowerCase();
56+
return s === 'true' || s === 'yes' || s === '1';
57+
}
5558
},
5659
[ALL_FIELD_TYPES.integer]: {
5760
// @ts-ignore

test/node/utils/data-processor-test.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,45 @@ test('Processor -> parseCsvRowsByFieldType -> boolean', t => {
447447
type: ALL_FIELD_TYPES.boolean
448448
};
449449

450-
const rows = [[null], ['0'], ['1'], ['True'], ['False'], ['0'], ['1'], ['true']];
450+
const rows = [
451+
[null],
452+
['0'],
453+
['1'],
454+
['True'],
455+
['False'],
456+
['0'],
457+
['1'],
458+
['true'],
459+
['yes'],
460+
['Yes'],
461+
['YES'],
462+
['no'],
463+
['No'],
464+
['NO'],
465+
['TRUE'],
466+
['false'],
467+
['FALSE']
468+
];
451469

452-
// is parsing '' meaningful, why not false
453-
const expected = [[null], [false], [true], [true], [false], [false], [true], [true]];
470+
const expected = [
471+
[null],
472+
[false],
473+
[true],
474+
[true],
475+
[false],
476+
[false],
477+
[true],
478+
[true],
479+
[true],
480+
[true],
481+
[true],
482+
[false],
483+
[false],
484+
[false],
485+
[true],
486+
[false],
487+
[false]
488+
];
454489

455490
parseCsvRowsByFieldType(rows, -1, field, 0);
456491
t.same(rows, expected, 'should parsed boolean properly');

0 commit comments

Comments
 (0)