Skip to content

Commit 3c38e1c

Browse files
Added more tests.
1 parent 5d2b053 commit 3c38e1c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/test_8000_dataframe.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,71 @@ def test_8027(self):
672672
fetched_data = self.__get_data_from_df(fetched_df)
673673
self.assertEqual(fetched_data, data)
674674

675+
def test_8028(self):
676+
"8028 - verify dtype for all Arrow types"
677+
query = """
678+
select
679+
cast(1 as number(10)) as col_int64,
680+
cast(1.23 as binary_double) as col_double,
681+
cast(7.14 as binary_float) as col_float,
682+
cast('abcd' as varchar2(10)) as col_string,
683+
cast(systimestamp as timestamp(0)) as col_ts_sec,
684+
cast(systimestamp as timestamp(3)) as col_ts_ms,
685+
cast(systimestamp as timestamp(6)) as col_ts_us,
686+
cast(systimestamp as timestamp(9)) as col_ts_ns,
687+
to_clob('abc') as col_large_string,
688+
utl_raw.cast_to_raw('abc2') as col_binary,
689+
to_blob(utl_raw.cast_to_raw('abc3')) as col_large_binary
690+
from dual
691+
"""
692+
decimal_query = (
693+
"select cast(123.45 as decimal(10, 2)) as col_decimal128"
694+
)
695+
696+
# determine dtype kind enumeration
697+
ora_df = self.conn.fetch_df_all("select user from dual")
698+
col = ora_df.get_column(0)
699+
dtype_kind = type(col.dtype[0])
700+
701+
expected_dtypes = {
702+
"COL_INT64": (dtype_kind.INT, 64, "l", "="),
703+
"COL_DOUBLE": (dtype_kind.FLOAT, 64, "g", "="),
704+
"COL_FLOAT": (dtype_kind.FLOAT, 64, "g", "="),
705+
"COL_STRING": (dtype_kind.STRING, 8, "u", "="),
706+
"COL_TS_SEC": (dtype_kind.DATETIME, 64, "tss:", "="),
707+
"COL_TS_MS": (dtype_kind.DATETIME, 64, "tsm:", "="),
708+
"COL_TS_US": (dtype_kind.DATETIME, 64, "tsu:", "="),
709+
"COL_TS_NS": (dtype_kind.DATETIME, 64, "tsn:", "="),
710+
"COL_LARGE_STRING": (dtype_kind.STRING, 8, "U", "="),
711+
"COL_BINARY": (dtype_kind.STRING, 8, "z", "="),
712+
"COL_LARGE_BINARY": (dtype_kind.STRING, 8, "Z", "="),
713+
"COL_DECIMAL128": (dtype_kind.DECIMAL, 128, "d:10.2", "="),
714+
}
715+
716+
# check query without fetch_decimals enabled
717+
ora_df = self.conn.fetch_df_all(query)
718+
for i, name in enumerate(ora_df.column_names()):
719+
col = ora_df.get_column(i)
720+
self.assertEqual(col.dtype, expected_dtypes[name])
721+
722+
# check query with fetch_decimals enabled
723+
with test_env.DefaultsContextManager("fetch_decimals", True):
724+
ora_df = self.conn.fetch_df_all(decimal_query)
725+
col = ora_df.get_column(0)
726+
self.assertEqual(col.dtype, expected_dtypes["COL_DECIMAL128"])
727+
728+
def test_8029(self):
729+
"8029 - verify get_buffers() with data frames containing null values"
730+
self.__populate_table(DATASET_2)
731+
statement = "select * from TestDataFrame order by Id"
732+
ora_df = self.conn.fetch_df_all(statement)
733+
country_col = ora_df.get_column_by_name("COUNTRY")
734+
buffers = country_col.get_buffers()
735+
self.assertEqual(len(buffers), 3)
736+
self.assertIsNotNone(buffers["data"])
737+
self.assertIsNotNone(buffers["offsets"])
738+
self.assertIsNotNone(buffers["validity"])
739+
675740

676741
if __name__ == "__main__":
677742
test_env.run_test_cases()

0 commit comments

Comments
 (0)