1

Here is my code snippet -

import datetime
from snowflake import connector
from snowflake.connector.pandas_tools import write_pandas
import pandas as pd
import pickle


class SnowflakeDataFetcher:
    def __init__(self):
        self.username = '***'
        self.password = '***'
        self.ctx_a = connector.connect(user=self.username, password=self.password, account='***',
                                         warehouse='***', database='***', schema='***', role='***')

    def upload_data(self, mode, data, tablename, virt_date):
        if mode == 'test_table_upload':
            data.info()
            query_output = write_pandas(self.ctx_a, data, table_name=tablename)
            print("Success!")


if __name__ == "__main__":
    snowflake_data_fetcher = SnowflakeDataFetcher()
    with open(r'***', 'rb') as gtc_data_pickle:
        gtc_data = pickle.load(gtc_data_pickle)
        snowflake_data_fetcher.upload_data('test_table_upload', gtc_data, "TEST_DATA", datetime.date(2021, 3, 17))

This is what the table on snowflake looks like: enter image description here

This what the dataframe looks like:

enter image description here

This is what my data.info() looks like for my gtc dataframe:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10056 entries, 0 to 10055
Data columns (total 3 columns):
 #   Column    Non-Null Count  Dtype 
---  ------    --------------  ----- 
 0   Datetime  10056 non-null  object
 1   Date      10056 non-null  object
 2   GTC Name  10056 non-null  object
dtypes: object(3)
memory usage: 235.8+ KB

I don't understand why I'm getting this error:

snowflake.connector.errors.ProgrammingError: 100072 (22000): NULL result in a non-nullable column

I don't see any null values in my dataframe and I'm still getting this error. Help!

1 Answer 1

1

It seems the issue is about the space character in "GTC Name". If you use GTC_Name (on both your DataFrame and table), it will work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.