Skip to content

Commit 4a9ba8f

Browse files
committed
handle string parsing similar to existin tap-s3 logic
1 parent 5ee1746 commit 4a9ba8f

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

singer/schema_generation.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,27 @@ def add_observations(acc, path, data):
2323
for item in data:
2424
add_observations(acc, path + ["array"], item)
2525
elif isinstance(data, str):
26-
parsed_data = None
2726
try:
28-
# If the string parses as a number, add an observation that it's a number
29-
parsed_data = float(data)
27+
# If the string parses as a int, add an observation that it's a integer
28+
int(data)
29+
add_observation(acc, path + ["integer"])
30+
return acc
31+
except (ValueError, TypeError):
32+
pass
33+
try:
34+
# If the string parses as a float, add an observation that it's a number
35+
float(data)
3036
add_observation(acc, path + ["number"])
31-
except ValueError:
32-
try:
33-
# If the string parses as a date, add an observation that it's a date
34-
parsed_data = dateutil.parser.parse(data)
35-
add_observation(acc, path + ["date"])
36-
except (dateutil.parser.ParserError, OverflowError):
37-
add_observation(acc, path + ["string"])
37+
return acc
38+
except (ValueError, TypeError):
39+
try:
40+
# If the string parses as a date, add an observation that it's a date
41+
dateutil.parser.parse(data)
42+
add_observation(acc, path + ["date"])
43+
return acc
44+
except (dateutil.parser.ParserError, OverflowError):
45+
pass
46+
add_observation(acc, path + ["string"])
3847
elif isinstance(data, bool):
3948
add_observation(acc, path + ["boolean"])
4049
elif isinstance(data, int):

0 commit comments

Comments
 (0)