Python sqlalchemy.sql.sqltypes.DateTime() Examples
The following are 10
code examples of sqlalchemy.sql.sqltypes.DateTime().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql.sqltypes
, or try the search function
.
Example #1
Source File: sanity.py From cum with Apache License 2.0 | 6 votes |
def test_datatype(self, table, column): """Tests that database column datatype matches the one defined in the models. """ database_column = self.find_database_column(table, column) if isinstance(column.type, sqltypes.String): expected_type = sqltypes.VARCHAR elif isinstance(column.type, sqltypes.Integer): expected_type = sqltypes.INTEGER elif isinstance(column.type, sqltypes.Boolean): expected_type = sqltypes.BOOLEAN elif isinstance(column.type, sqltypes.DateTime): expected_type = sqltypes.DATETIME if not isinstance(database_column['type'], expected_type): self.errors.append( DatatypeMismatch(table, database_column, expected_type, parent=self) )
Example #2
Source File: test_sql.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_notna_dtype(self): cols = {'Bool': Series([True, None]), 'Date': Series([datetime(2012, 5, 1), None]), 'Int': Series([1, None], dtype='object'), 'Float': Series([1.1, None]) } df = DataFrame(cols) tbl = 'notna_dtype_test' df.to_sql(tbl, self.conn) returned_df = sql.read_sql_table(tbl, self.conn) # noqa meta = sqlalchemy.schema.MetaData(bind=self.conn) meta.reflect() if self.flavor == 'mysql': my_type = sqltypes.Integer else: my_type = sqltypes.Boolean col_dict = meta.tables[tbl].columns assert isinstance(col_dict['Bool'].type, my_type) assert isinstance(col_dict['Date'].type, sqltypes.DateTime) assert isinstance(col_dict['Int'].type, sqltypes.Integer) assert isinstance(col_dict['Float'].type, sqltypes.Float)
Example #3
Source File: test_sql.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_notna_dtype(self): cols = {'Bool': Series([True, None]), 'Date': Series([datetime(2012, 5, 1), None]), 'Int': Series([1, None], dtype='object'), 'Float': Series([1.1, None]) } df = DataFrame(cols) tbl = 'notna_dtype_test' df.to_sql(tbl, self.conn) returned_df = sql.read_sql_table(tbl, self.conn) # noqa meta = sqlalchemy.schema.MetaData(bind=self.conn) meta.reflect() if self.flavor == 'mysql': my_type = sqltypes.Integer else: my_type = sqltypes.Boolean col_dict = meta.tables[tbl].columns assert isinstance(col_dict['Bool'].type, my_type) assert isinstance(col_dict['Date'].type, sqltypes.DateTime) assert isinstance(col_dict['Int'].type, sqltypes.Integer) assert isinstance(col_dict['Float'].type, sqltypes.Float)
Example #4
Source File: test_sql.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_notna_dtype(self): cols = {'Bool': Series([True, None]), 'Date': Series([datetime(2012, 5, 1), None]), 'Int': Series([1, None], dtype='object'), 'Float': Series([1.1, None]) } df = DataFrame(cols) tbl = 'notna_dtype_test' df.to_sql(tbl, self.conn) returned_df = sql.read_sql_table(tbl, self.conn) # noqa meta = sqlalchemy.schema.MetaData(bind=self.conn) meta.reflect() if self.flavor == 'mysql': my_type = sqltypes.Integer else: my_type = sqltypes.Boolean col_dict = meta.tables[tbl].columns assert isinstance(col_dict['Bool'].type, my_type) assert isinstance(col_dict['Date'].type, sqltypes.DateTime) assert isinstance(col_dict['Int'].type, sqltypes.Integer) assert isinstance(col_dict['Float'].type, sqltypes.Float)
Example #5
Source File: test_sql.py From recruit with Apache License 2.0 | 5 votes |
def test_notna_dtype(self): cols = {'Bool': Series([True, None]), 'Date': Series([datetime(2012, 5, 1), None]), 'Int': Series([1, None], dtype='object'), 'Float': Series([1.1, None]) } df = DataFrame(cols) tbl = 'notna_dtype_test' df.to_sql(tbl, self.conn) returned_df = sql.read_sql_table(tbl, self.conn) # noqa meta = sqlalchemy.schema.MetaData(bind=self.conn) meta.reflect() if self.flavor == 'mysql': my_type = sqltypes.Integer else: my_type = sqltypes.Boolean col_dict = meta.tables[tbl].columns assert isinstance(col_dict['Bool'].type, my_type) assert isinstance(col_dict['Date'].type, sqltypes.DateTime) assert isinstance(col_dict['Int'].type, sqltypes.Integer) assert isinstance(col_dict['Float'].type, sqltypes.Float)
Example #6
Source File: test_sql.py From vnpy_crypto with MIT License | 5 votes |
def test_sqlalchemy_type_mapping(self): # Test Timestamp objects (no datetime64 because of timezone) (GH9085) df = DataFrame({'time': to_datetime(['201412120154', '201412110254'], utc=True)}) db = sql.SQLDatabase(self.conn) table = sql.SQLTable("test_type", db, frame=df) assert isinstance(table.table.c['time'].type, sqltypes.DateTime)
Example #7
Source File: test_sql.py From vnpy_crypto with MIT License | 5 votes |
def test_notna_dtype(self): cols = {'Bool': Series([True, None]), 'Date': Series([datetime(2012, 5, 1), None]), 'Int': Series([1, None], dtype='object'), 'Float': Series([1.1, None]) } df = DataFrame(cols) tbl = 'notna_dtype_test' df.to_sql(tbl, self.conn) returned_df = sql.read_sql_table(tbl, self.conn) # noqa meta = sqlalchemy.schema.MetaData(bind=self.conn) meta.reflect() if self.flavor == 'mysql': my_type = sqltypes.Integer else: my_type = sqltypes.Boolean col_dict = meta.tables[tbl].columns assert isinstance(col_dict['Bool'].type, my_type) assert isinstance(col_dict['Date'].type, sqltypes.DateTime) assert isinstance(col_dict['Int'].type, sqltypes.Integer) assert isinstance(col_dict['Float'].type, sqltypes.Float)
Example #8
Source File: database.py From walle-web with Apache License 2.0 | 5 votes |
def parse_operator(cls, filter_name_dict): """ 用来返回sqlalchemy query对象filter使用的表达式 Args: filter_name_dict (dict): 过滤条件dict { 'last_name': {'eq': 'wang'}, # 如果是dic使用key作为操作符 'age': {'>': 12} } Returns: binary_expression_list (lambda list) """ def _change_type(cls, field, value): """ 有些表字段比如DateTime类型比较的时候需要转换类型, 前端传过来的都是字符串,Date等类型没法直接相比较,需要转成Date类型 Args: cls (class): Model class field (str): Model class field value (str): value need to compare """ field_type = getattr(cls, field).type if isinstance(field_type, Date): return date_str_to_obj(value) elif isinstance(field_type, DateTime): return datetime_str_to_obj(value) else: return value binary_expression_list = [] for field, op_dict in list(filter_name_dict.items()): for op, op_val in list(op_dict.items()): op_val = _change_type(cls, field, op_val) if op in OPERATOR_FUNC_DICT: binary_expression_list.append( OPERATOR_FUNC_DICT[op](cls, field, op_val) ) return binary_expression_list
Example #9
Source File: test_sql.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_sqlalchemy_type_mapping(self): # Test Timestamp objects (no datetime64 because of timezone) (GH9085) df = DataFrame({'time': to_datetime(['201412120154', '201412110254'], utc=True)}) db = sql.SQLDatabase(self.conn) table = sql.SQLTable("test_type", db, frame=df) assert isinstance(table.table.c['time'].type, sqltypes.DateTime)
Example #10
Source File: test_sql.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_sqlalchemy_type_mapping(self): # Test Timestamp objects (no datetime64 because of timezone) (GH9085) df = DataFrame({'time': to_datetime(['201412120154', '201412110254'], utc=True)}) db = sql.SQLDatabase(self.conn) table = sql.SQLTable("test_type", db, frame=df) assert isinstance(table.table.c['time'].type, sqltypes.DateTime)