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

Force schema for cats columns #166

Merged
merged 1 commit into from
Feb 15, 2023
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
36 changes: 28 additions & 8 deletions fink_client/scripts/fink_datatransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def main():
print('No alerts the last {} seconds ({} polled)... Exiting'.format(maxtimeout, poll_number))
break

# known mismatches between partitions
# see https://github.com/astrolabsoftware/fink-client/issues/165
if 'cats_broad_max_prob' in pdf.columns:
pdf['cats_broad_max_prob'] = pdf['cats_broad_max_prob'].astype('float')

if 'cats_broad_class' in pdf.columns:
pdf['cats_broad_class'] = pdf['cats_broad_class'].astype('float')

if 'tracklet' in pdf.columns:
pdf['tracklet'] = pdf['tracklet'].astype('str')

Expand All @@ -140,14 +148,26 @@ def main():
elif args.partitionby == 'classId':
partitioning = ['classId']

pq.write_to_dataset(
table,
args.outdir,
schema=table_schema,
basename_template='part-{{i}}-{}.parquet'.format(poll_number),
partition_cols=partitioning,
existing_data_behavior='overwrite_or_ignore'
)
try:
pq.write_to_dataset(
table,
args.outdir,
schema=table_schema,
basename_template='part-{{i}}-{}.parquet'.format(poll_number),
partition_cols=partitioning,
existing_data_behavior='overwrite_or_ignore'
)
except pa.lib.ArrowTypeError:
print('Schema mismatch detected')
table_schema_ = table.schema
pq.write_to_dataset(
table,
args.outdir,
schema=table_schema_,
basename_template='part-{{i}}-{}.parquet'.format(poll_number),
partition_cols=partitioning,
existing_data_behavior='overwrite_or_ignore'
)

poll_number += len(msgs)
if args.verbose:
Expand Down