Repository: duckdb/duckdb
File: tools/pythonpkg/tests/fast/pandas/test_pandas_types.py (Python)

Code before:
            "UInt16",
            "uint32",
            "UInt32",
            "uint64",
            "UInt64",
            "int8",
            "Int8",
            "int16",
            "Int16",
            "int32",
            "Int32",
            "int64",
            "Int64",
            "float32",
            "Float32",
            "float64",
            "Float64"
        ]

        # Generate a dataframe with all the types, in the form of:
        # b=type1,
        # c=type2
        # ..
        data = {}
        for i, dtype in enumerate(data_types):
            data[chr(ord("a")+i)] = base_df.a.astype(dtype)

        df = pd.DataFrame.from_dict(data)
        out_df = duckdb.default_connection.execute('select * from df').df()

        # Verify that the types in the out_df are correct
        # FIXME: we don't support outputting pandas specific types (i.e UInt64)
        for i, item in enumerate(data_types):
            column_name = chr(ord("a")+i)
            assert(str(df[column_name].dtype) == item)
        for i, item in enumerate(data_types):
            column_name = chr(ord("a")+i)
            assert(str(out_df[column_name].dtype) == item.lower())

    def test_pandas_unsigned(self, duckdb_cursor):
        unsigned_types = ['uint8','uint16','uint32','uint64']
        data = numpy.array([0,1,2,3])
        for u_type in unsigned_types:
            round_trip(data,u_type)

    def test_pandas_bool(self, duckdb_cursor):
        data = numpy.array([True,False,False,True])
        round_trip(data,'bool')
    
    def test_pandas_boolean(self, duckdb_cursor):
        data = numpy.array([True,None,pd.NA,numpy.nan,True])

Review comment (suggestion):
Could just do `for letter, dtype in zip(string.alphabet, ...)` here

Code after:
            "uint16",
            "UInt16",
            "uint32",
            "UInt32",
            "uint64",
            "UInt64",
            "int8",
            "Int8",
            "int16",
            "Int16",
            "int32",
            "Int32",
            "int64",
            "Int64",
            "float32",
            "Float32",
            "float64",
            "Float64"
        ]

        # Generate a dataframe with all the types, in the form of:
        # b=type1,
        # c=type2
        # ..
        data = {}
        for letter, dtype in zip(string.ascii_lowercase, data_types):
            data[letter] = base_df.a.astype(dtype)

        df = pd.DataFrame.from_dict(data)
        conn = duckdb.connect()
        out_df = conn.execute('select * from df').df()

        # Verify that the types in the out_df are correct
        # FIXME: we don't support outputting pandas specific types (i.e UInt64)
        for letter, item in zip(string.ascii_lowercase, data_types):
            column_name = letter
            assert(str(out_df[column_name].dtype) == item.lower())

    def test_pandas_unsigned(self, duckdb_cursor):
        unsigned_types = ['uint8','uint16','uint32','uint64']
        data = numpy.array([0,1,2,3])
        for u_type in unsigned_types:
            round_trip(data,u_type)

    def test_pandas_bool(self, duckdb_cursor):
        data = numpy.array([True,False,False,True])
        round_trip(data,'bool')
    
    def test_pandas_boolean(self, duckdb_cursor):
        data = numpy.array([True,None,pd.NA,numpy.nan,True])
        df_in = pd.DataFrame({