OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dtypes.py
Go to the documentation of this file.
1 """
2 https://www.python.org/dev/peps/pep-0249/#type-objects
3 """
4 import datetime
5 import time
6 from omnisci.common.ttypes import TDatumType
7 
8 T = TDatumType
9 
10 
11 class DataType:
12  def __init__(self, matches):
13  self._matches = set(matches)
14 
15  def __eq__(self, other):
16  return other in self._matches
17 
18  def __ne__(self, other):
19  return not (self == other)
20 
21  def __hash__(self):
22  return hash(tuple(self._matches))
23 
24 
25 Binary = memoryview
26 Date = datetime.date
27 Time = datetime.time
28 Timestamp = datetime.datetime
29 
30 BINARY = DataType([])
31 STRING = DataType(
32  [
33  T.STR,
34  T.POINT,
35  T.LINESTRING,
36  T.POLYGON,
37  T.MULTIPOLYGON,
38  T.GEOMETRY,
39  T.GEOGRAPHY,
40  ]
41 )
42 NUMBER = DataType(
43  [
44  T.SMALLINT,
45  T.INT,
46  T.BIGINT,
47  T.FLOAT,
48  T.DECIMAL,
49  T.DOUBLE,
50  T.BOOL,
51  T.TINYINT,
52  ]
53 )
54 DATETIME = DataType([T.DATE, T.TIME, T.TIMESTAMP])
55 ROWID = DataType([])
56 
57 
58 def DateFromTicks(ticks):
59  return Date(*time.localtime(ticks)[:3])
60 
61 
62 def TimeFromTicks(ticks):
63  return Time(*time.localtime(ticks)[3:6])
64 
65 
66 def TimestampFromTicks(ticks):
67  return Timestamp(*time.localtime(ticks)[:6])
def TimestampFromTicks
Definition: dtypes.py:66
def TimeFromTicks
Definition: dtypes.py:62
def DateFromTicks
Definition: dtypes.py:58