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

keep null values in to_singer if catalog_schema #43

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
15 changes: 10 additions & 5 deletions gluestick/singer.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,13 @@ def to_singer(
allow_objects: boolean
Allow or not objects to the parsed, if false defaults types to str.

"""
"""
if allow_objects and not catalog_schema:
df = df.dropna(how="all", axis=1)

catalog_schema = os.environ.get("USE_CATALOG_SCHEMA", "false").lower() == "true"
if catalog_schema:
# it'll allow_objects but keeping all columns
allow_objects = True
# get schema from catalog
schema = get_catalog_schema(stream)
Expand All @@ -314,9 +318,6 @@ def to_singer(
elif unified_model:
schema = unwrap_json_schema(unified_model.model_json_schema())

if allow_objects:
df = df.dropna(how="all", axis=1)

df, header_map = gen_singer_header(df, allow_objects, schema, catalog_schema)
output = os.path.join(output_dir, filename)
mode = "a" if os.path.isfile(output) else "w"
Expand All @@ -326,7 +327,11 @@ def to_singer(
singer.write_schema(stream, header_map, keys)
with Transformer() as transformer:
for i, row in df.iterrows():
filtered_row = row.dropna().to_dict()
if not catalog_schema:
filtered_row = row.dropna()
else:
filtered_row = row.where(pd.notna(row), None)
filtered_row = filtered_row.to_dict()
filtered_row = deep_convert_datetimes(filtered_row)
rec = transformer.transform(filtered_row, header_map)
singer.write_record(stream, rec)
Expand Down
Loading