Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unflatten: How to include literal commas and semi-colons in a plain array of strings? #427

Open
duncandewhurst opened this issue Aug 15, 2023 · 2 comments
Labels
RDLS Issues and PRs relating to the Risk Data Library Standard

Comments

@duncandewhurst
Copy link
Contributor

From GFDRR/rdls-spreadsheet-template#3 (comment), what is the correct syntax to produce the following JSON output?

{
  "authors": [
    "Smith, John",
    "Bloggs, Joe"
   ]
}
@duncandewhurst
Copy link
Contributor Author

I think I found the relevant bit of code, there doesn't seem to be any support for escaping separators:

elif type_string in ("array", "array_array", "string_array", "number_array"):
value = str(value)
if type_string == "number_array":
try:
if "," in value:
return [
[Decimal(y) for y in x.split(",")] for x in value.split(";")
]
else:
return [Decimal(x) for x in value.split(";")]
except (TypeError, ValueError, InvalidOperation):
warn(
_(
'Non-numeric value "{}" found in number array column, returning as string array instead).'
).format(value),
DataErrorWarning,
)
if "," in value:
return [x.split(",") for x in value.split(";")]
else:
return value.split(";")

@duncandewhurst duncandewhurst added the RDLS Issues and PRs relating to the Risk Data Library Standard label Aug 21, 2023
@duncandewhurst
Copy link
Contributor Author

Confirmed that this isn't currently possible. In RDLS, for the time being, we can inform spreadsheet users that values must not contain semicolons or commas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RDLS Issues and PRs relating to the Risk Data Library Standard
Projects
None yet
Development

No branches or pull requests

1 participant