|
18 | 18 | import time
|
19 | 19 | import uuid
|
20 | 20 |
|
21 |
| -from odps.tests.core import tn, pandas_case |
| 21 | +from odps import types as odps_types |
| 22 | +from odps.tests.core import tn, pandas_case, odps2_typed_case |
22 | 23 | from odps.df.backends.tests.core import TestBase
|
23 | 24 | from odps.config import options
|
24 | 25 | from odps.compat import unittest
|
25 | 26 | from odps.models import Schema, Instance
|
26 |
| -from odps.errors import ODPSError |
27 | 27 | from odps.df.backends.engine import MixedEngine
|
28 | 28 | from odps.df.backends.odpssql.engine import ODPSSQLEngine
|
29 | 29 | from odps.df.backends.pd.engine import PandasEngine
|
@@ -194,6 +194,31 @@ def testPandasPersist(self):
|
194 | 194 | finally:
|
195 | 195 | self.odps.delete_table(tmp_table_name)
|
196 | 196 |
|
| 197 | + @odps2_typed_case |
| 198 | + def testPandasPersistODPS2(self): |
| 199 | + import pandas as pd |
| 200 | + import numpy as np |
| 201 | + |
| 202 | + data_int8 = np.random.randint(0, 10, (1,), dtype=np.int8) |
| 203 | + data_int16 = np.random.randint(0, 10, (1,), dtype=np.int16) |
| 204 | + data_int32 = np.random.randint(0, 10, (1,), dtype=np.int32) |
| 205 | + data_int64 = np.random.randint(0, 10, (1,), dtype=np.int64) |
| 206 | + data_float32 = np.random.random((1,)).astype(np.float32) |
| 207 | + data_float64 = np.random.random((1,)).astype(np.float64) |
| 208 | + |
| 209 | + df = DataFrame(pd.DataFrame(dict(data_int8=data_int8, data_int16=data_int16, |
| 210 | + data_int32=data_int32, data_int64=data_int64, |
| 211 | + data_float32=data_float32, data_float64=data_float64))) |
| 212 | + tmp_table_name = tn('pyodps_test_mixed_persist_odps2_types') |
| 213 | + |
| 214 | + self.odps.delete_table(tmp_table_name, if_exists=True) |
| 215 | + df.persist(tmp_table_name, lifecycle=1, drop_table=True, odps=self.odps) |
| 216 | + |
| 217 | + t = self.odps.get_table(tmp_table_name) |
| 218 | + expected_types = [odps_types.tinyint, odps_types.smallint, odps_types.int_, |
| 219 | + odps_types.bigint, odps_types.float_, odps_types.double] |
| 220 | + self.assertEqual(expected_types, t.schema.types) |
| 221 | + |
197 | 222 | def testExecuteCacheTable(self):
|
198 | 223 | df = self.odps_df[self.odps_df.name == 'name1']
|
199 | 224 | result = df.execute().values
|
|
0 commit comments