Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pypfb"
version = "0.5.23"
version = "0.5.24"
description = "Python SDK for PFB format"
authors = ["CTDS UChicago <[email protected]>"]
license = "Apache-2.0"
Expand Down
21 changes: 14 additions & 7 deletions src/pfb/importers/tsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def from_tsv(ctx, path, schema, program, project):
with PFBReader(schema) as reader:
writer.copy_schema(reader)

writer.write(_from_tsv(writer.metadata, writer.schema, path, program, project))
writer.write(
_from_tsv(writer.metadata, writer.schema, path, program, project)
)
except Exception:
click.secho("Failed!", fg="red", bold=True, err=True)
raise
Expand Down Expand Up @@ -88,7 +90,12 @@ def convert_types(val, field_type):
return None
return str(val)
elif field_type == "float":
if val is None or val.strip() == "" or val.strip() == "null" or val.strip() == "Null":
if (
val is None
or val.strip() == ""
or val.strip() == "null"
or val.strip() == "Null"
):
return None
return float(val)
elif field_type == "integer" or field_type == "long":
Expand All @@ -102,6 +109,7 @@ def convert_types(val, field_type):
# finally if the type doesn't match any case then we return the supplied value
return val


def get_type_from_schema(schema, node, field):
nodes = None
for n in schema:
Expand Down Expand Up @@ -130,7 +138,6 @@ def get_type_from_schema(schema, node, field):
return field_type



def _convert_tsv(node_name, tsv_record, program, project, link_dests):
relations = []
try:
Expand All @@ -154,12 +161,13 @@ def _convert_tsv(node_name, tsv_record, program, project, link_dests):
"dst_name": link_dests[node_name][v],
}
)

# array typing being passed off as string
if (
type(tsv_record[item]) == str
and "[" in tsv_record[item]
and "]" in tsv_record[item]
and len(tsv_record[item]) > 0
and tsv_record[item][0] == "["
and tsv_record[item][-1] == "]"
):
arrayStrip = tsv_record[item].strip("[']")
vals[item] = arrayStrip.split(",")
Expand All @@ -169,7 +177,6 @@ def _convert_tsv(node_name, tsv_record, program, project, link_dests):
{"dst_id": tsv_record[item], "dst_name": item.split(".")[0]}
)
to_del.append(item)


for i in to_del:
if i in vals:
Expand Down