wherobots-python-dbapi 0.7.2__tar.gz → 0.7.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wherobots-python-dbapi
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: Python DB-API driver for Wherobots DB
5
5
  License: Apache 2.0
6
6
  Author: Maxime Petazzoni
@@ -14,8 +14,9 @@ Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Requires-Dist: StrEnum (>=0.4.15,<0.5.0)
16
16
  Requires-Dist: cbor2 (>=5.6.3,<6.0.0)
17
- Requires-Dist: pandas (>=2.2.2,<3.0.0)
18
- Requires-Dist: pyarrow (>=15.0.2,<16.0.0)
17
+ Requires-Dist: numpy (<2)
18
+ Requires-Dist: pandas (>=2.1.0,<3.0.0)
19
+ Requires-Dist: pyarrow (>=14.0.2,<15.0.0)
19
20
  Requires-Dist: requests (>=2.31.0,<3.0.0)
20
21
  Requires-Dist: tenacity (>=8.2.3,<9.0.0)
21
22
  Requires-Dist: websockets (>=12.0,<13.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "wherobots-python-dbapi"
3
- version = "0.7.2"
3
+ version = "0.7.3"
4
4
  description = "Python DB-API driver for Wherobots DB"
5
5
  authors = ["Maxime Petazzoni <max@wherobots.com>"]
6
6
  license = "Apache 2.0"
@@ -16,10 +16,12 @@ python = "^3.9"
16
16
  requests = "^2.31.0"
17
17
  websockets = "^12.0"
18
18
  tenacity = "^8.2.3"
19
- pyarrow = "^15.0.2"
19
+ pyarrow = "^14.0.2"
20
20
  cbor2 = "^5.6.3"
21
- pandas = "^2.2.2"
21
+ pandas = "^2.1.0"
22
22
  StrEnum = "^0.4.15"
23
+ # pyarrow 14.0.2 doesn't limit numpy < 2, but it should, we do it here
24
+ numpy = "<2"
23
25
 
24
26
  [tool.poetry.group.dev.dependencies]
25
27
  mypy = "^1.8.0"
@@ -1,8 +1,18 @@
1
1
  import queue
2
- from typing import Any, Optional
2
+ from typing import Any, Optional, List, Tuple
3
3
 
4
4
  from .errors import ProgrammingError, DatabaseError
5
5
 
6
+ _TYPE_MAP = {
7
+ "object": "STRING",
8
+ "int64": "NUMBER",
9
+ "float64": "NUMBER",
10
+ "datetime64[ns]": "DATETIME",
11
+ "timedelta[ns]": "DATETIME",
12
+ "bool": "NUMBER", # Assuming boolean is stored as number
13
+ "bytes": "BINARY",
14
+ }
15
+
6
16
 
7
17
  class Cursor:
8
18
 
@@ -17,14 +27,14 @@ class Cursor:
17
27
 
18
28
  # Description and row count are set by the last executed operation.
19
29
  # Their default values are defined by PEP-0249.
20
- self.__description: Optional[str] = None
30
+ self.__description: Optional[List[Tuple]] = None
21
31
  self.__rowcount: int = -1
22
32
 
23
33
  # Array-size is also defined by PEP-0249 and is expected to be read/writable.
24
34
  self.arraysize: int = 1
25
35
 
26
36
  @property
27
- def description(self) -> Optional[str]:
37
+ def description(self) -> Optional[List[Tuple]]:
28
38
  return self.__description
29
39
 
30
40
  @property
@@ -34,7 +44,7 @@ class Cursor:
34
44
  def __on_execution_result(self, result) -> None:
35
45
  self.__queue.put(result)
36
46
 
37
- def __get_results(self) -> Optional[list[Any]]:
47
+ def __get_results(self) -> Optional[List[Tuple[Any, ...]]]:
38
48
  if not self.__current_execution_id:
39
49
  raise ProgrammingError("No query has been executed yet")
40
50
  if self.__results is not None:
@@ -43,8 +53,23 @@ class Cursor:
43
53
  result = self.__queue.get()
44
54
  if isinstance(result, DatabaseError):
45
55
  raise result
56
+
46
57
  self.__rowcount = len(result)
47
58
  self.__results = result
59
+ if not result.empty:
60
+ self.__description = [
61
+ (
62
+ col_name, # name
63
+ _TYPE_MAP.get(str(result[col_name].dtype), "STRING"), # type_code
64
+ None, # display_size
65
+ result[col_name].memory_usage(), # internal_size
66
+ None, # precision
67
+ None, # scale
68
+ True, # null_ok; Assuming all columns can accept NULL values
69
+ )
70
+ for col_name in result.columns
71
+ ]
72
+
48
73
  return self.__results
49
74
 
50
75
  def execute(self, operation: str, parameters: dict[str, Any] = None):
@@ -54,6 +79,7 @@ class Cursor:
54
79
  self.__results = None
55
80
  self.__current_row = 0
56
81
  self.__rowcount = -1
82
+ self.__description = None
57
83
 
58
84
  sql = operation.format(**(parameters or {}))
59
85
  self.__current_execution_id = self.__exec_fn(sql, self.__on_execution_result)