I am using beam python SDK to read two CSV files using apache_beam.dataframe.io.read_csv library.
subscriber_data = (p | 'Read Subscriber File' >> read_csv('subscriber_data.csv'))
address_data = (p | 'Read address File' >> read_csv('address_data.csv'))
then trying to merge these files using pd.merge left join using the below code
subscriber_address_df = subscriber_data.merge(address_data.set_index('address_id').state,
right_index=True,
left_on='address_id',
how='left')
once I tried to print the subscriber_address_df using the below code
to_pcollection(subscriber_address_df , include_indexes=False) | beam.Map(print)
I got this error:
ValueError: Attempted to encode null for non-nullable field "state". [while running 'Unbatch 'merge_DataFrame_2137267343520'/ParDo(_UnbatchNoIndex)']
How can I solve this error?
My understanding is, this error happened because of null values generated from left join in non-nullable column state in the data frame schema.
I tried to switch the dataframe to Pcollection using to_pcollection and assign schema with nullable columns for that pcollection using .with_output_types then switch back to dataframe to_dataframe, but it did not work