OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
_utils.py
Go to the documentation of this file.
1 import datetime
2 import numpy as np
3 
4 
5 def seconds_to_time(seconds):
6  """Convert seconds since midnight to a datetime.time"""
7  m, s = divmod(seconds, 60)
8  h, m = divmod(m, 60)
9  return datetime.time(h, m, s)
10 
11 
12 def time_to_seconds(time):
13  """Convert a datetime.time to seconds since midnight"""
14  if time is None:
15  return None
16  return 3600 * time.hour + 60 * time.minute + time.second
17 
18 
19 def datetime_in_precisions(epoch, precision):
20  """Convert epoch time value into s, ms, us, ns"""
21  base = datetime.datetime(1970, 1, 1)
22  if precision == 0:
23  return base + datetime.timedelta(seconds=epoch)
24  elif precision == 3:
25  seconds, modulus = divmod(epoch, 1000)
26  return base + datetime.timedelta(seconds=seconds, milliseconds=modulus)
27  elif precision == 6:
28  seconds, modulus = divmod(epoch, 1000000)
29  return base + datetime.timedelta(seconds=seconds, microseconds=modulus)
30  elif precision == 9:
31  return np.datetime64(epoch, 'ns')
32  else:
33  raise TypeError("Invalid timestamp precision: {}".format(precision))
34 
35 
36 def date_to_seconds(arr):
37  """Converts date into seconds"""
38 
39  return arr.apply(lambda x: np.datetime64(x, "s").astype(int))
40 
41 
42 mapd_to_slot = {
43  'BOOL': 'int_col',
44  'BOOLEAN': 'int_col',
45  'SMALLINT': 'int_col',
46  'INT': 'int_col',
47  'INTEGER': 'int_col',
48  'BIGINT': 'int_col',
49  'FLOAT': 'real_col',
50  'DECIMAL': 'int_col',
51  'DOUBLE': 'real_col',
52  'TIMESTAMP': 'int_col',
53  'DATE': 'int_col',
54  'TIME': 'int_col',
55  'STR': 'str_col',
56  'POINT': 'str_col',
57  'MULTIPOINT': 'str_col',
58  'LINESTRING': 'str_col',
59  'MULTILINESTRING': 'str_col',
60  'POLYGON': 'str_col',
61  'MULTIPOLYGON': 'str_col',
62  'TINYINT': 'int_col',
63  'GEOMETRY': 'str_col',
64  'GEOGRAPHY': 'str_col',
65 }
66 
67 
68 mapd_to_na = {
69  'BOOL': -128,
70  'BOOLEAN': -128,
71  'SMALLINT': -32768,
72  'INT': -2147483648,
73  'INTEGER': -2147483648,
74  'BIGINT': -9223372036854775808,
75  'FLOAT': 0,
76  'DECIMAL': 0,
77  'DOUBLE': 0,
78  'TIMESTAMP': -9223372036854775808,
79  'DATE': -9223372036854775808,
80  'TIME': -9223372036854775808,
81  'STR': '',
82  'POINT': '',
83  'MULTIPOINT': '',
84  'LINESTRING': '',
85  'MULTILINESTRING': '',
86  'POLYGON': '',
87  'MULTIPOLYGON': '',
88  'TINYINT': -128,
89  'GEOMETRY': '',
90  'GEOGRAPHY': '',
91 }
def seconds_to_time
Definition: _utils.py:5
def datetime_in_precisions
Definition: _utils.py:19
def time_to_seconds
Definition: _utils.py:12
def date_to_seconds
Definition: _utils.py:36