Skip to content

Parse filename-like attribute values as full strings, not leading digits#1789

Open
mattdawkins wants to merge 1 commit into
mainfrom
fix/attribute-string-values
Open

Parse filename-like attribute values as full strings, not leading digits#1789
mattdawkins wants to merge 1 commit into
mainfrom
fix/attribute-string-values

Conversation

@mattdawkins

Copy link
Copy Markdown
Member

Problem

A detection attribute whose value is a filename like 0123ABC456 (numbers, letters, numbers — e.g. the source_image attributes the sea-lion suppressor writes) displayed as just 123: only the first digit group survived import.

Cause

  • Desktop CSV parser (_deduceType in serializers/viame.ts) used parseFloat, which parses a leading numeric prefix (parseFloat('0123ABC456') === 123), replacing the string with a number.
  • Desktop attribute-definition inference (attributeProcessor.ts) used the same parseFloat check, so such attributes were also typed as numbers.
  • Server parser (dive_utils/serializers/viame.py) had the adjacent Python gotcha: float() accepts underscore digit separators (float('20240624_120000') == 20240624120000.0) and inf/nan spellings, corrupting underscore-separated filename stems the same way.

Fix

  • Desktop _deduceType uses Number(), which converts only fully numeric strings (with an explicit empty/whitespace guard, since Number('') === 0).
  • Desktop attributeProcessor infers number only for fully numeric values.
  • Server value parsing and type inference both require a strictly numeric string (regex full-match) before converting.

Real numbers (12.5, -3, 1e5) and booleans still convert exactly as before. Regression test parses (atr) values with filename-like, underscore-separated, numeric, and boolean content and checks both values and inferred datatypes.

Note: values already truncated in previously saved annotations can't be recovered — re-importing the source CSV restores them.

🤖 Generated with Claude Code

Attribute values such as '0123ABC456' (e.g. the source_image filenames
the sea-lion suppressor writes) were truncated to their leading digits:
the desktop CSV parser used parseFloat, which accepts a numeric prefix,
so the value became the number 123. The attribute-definition inference
had the same bug and typed such attributes as numbers.

- Desktop _deduceType now uses Number(), which only converts fully
  numeric strings (empty/whitespace stays a string).
- Desktop attributeProcessor infers 'number' only for fully numeric
  values.
- The server parser had the adjacent Python gotcha: float() accepts
  underscore digit separators ('20240624_120000') and inf/nan
  spellings. Both its value parsing and type inference now require a
  strictly numeric string.

Includes a regression test parsing (atr) values with filename-like,
numeric, and boolean content.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant