ptars 0.0.1rc1__cp311-cp311-macosx_10_12_x86_64.whl → 0.0.2rc2__cp311-cp311-macosx_10_12_x86_64.whl

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.
Binary file
ptars/internal.py CHANGED
@@ -1,3 +1,7 @@
1
+ import warnings
2
+
3
+ import pyarrow as pa
4
+ from google._upb._message import Message, MessageMeta
1
5
  from google.protobuf.descriptor import Descriptor, FileDescriptor
2
6
  from google.protobuf.descriptor_pb2 import FileDescriptorProto
3
7
 
@@ -10,16 +14,21 @@ def _file_descriptor_to_bytes(fd: FileDescriptor) -> bytes:
10
14
  return file_descriptor.SerializeToString()
11
15
 
12
16
 
13
- def get_dependencies(
17
+ def _get_dependencies(
14
18
  file_descriptor: FileDescriptor, results: list[FileDescriptor] = None
15
19
  ) -> list[FileDescriptor]:
20
+ """
21
+ Return list of FileDescriptor that this file depends on, including this one.
22
+
23
+ Results are in topological order (least dependent first).
24
+ """
16
25
  if results is None:
17
26
  results = []
18
- results.append(file_descriptor)
19
27
  for dependency in file_descriptor.dependencies:
20
28
  if dependency not in results:
21
- get_dependencies(dependency, results)
22
- return results
29
+ _get_dependencies(dependency, results)
30
+ results.append(file_descriptor)
31
+ return results[::-1]
23
32
 
24
33
 
25
34
  class HandlerPool:
@@ -28,16 +37,30 @@ class HandlerPool:
28
37
  self._pool = {}
29
38
 
30
39
  def get_for_message(self, descriptor: Descriptor) -> MessageHandler:
40
+ if isinstance(descriptor, MessageMeta):
41
+ warnings.warn(
42
+ f"Received {MessageMeta.__name__} instead of {Descriptor.__name__}"
43
+ )
44
+ descriptor = descriptor.DESCRIPTOR
45
+ if not isinstance(descriptor, Descriptor):
46
+ raise TypeError(f"Expecting {Descriptor.__name__}")
47
+
31
48
  assert isinstance(descriptor, Descriptor)
32
49
  try:
33
- self._pool[descriptor.full_name]
50
+ return self._pool[descriptor.full_name]
34
51
  except KeyError:
35
52
  file_descriptor = descriptor.file
36
53
 
37
- dependencies = get_dependencies(file_descriptor)
54
+ dependencies = _get_dependencies(file_descriptor)
38
55
  payloads = [_file_descriptor_to_bytes(d) for d in dependencies]
39
56
  message_handler = self._proto_cache.create_for_message(
40
57
  "." + descriptor.full_name, payloads
41
58
  )
42
59
  self._pool[descriptor.full_name] = message_handler
43
60
  return message_handler
61
+
62
+ def messages_to_record_batch(
63
+ self, messages: list[Message], descriptor: Descriptor
64
+ ) -> pa.RecordBatch:
65
+ handler = self.get_for_message(descriptor)
66
+ return handler.list_to_record_batch([m.SerializeToString() for m in messages])
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ptars
3
- Version: 0.0.1rc1
3
+ Version: 0.0.2rc2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Operating System :: POSIX :: Linux
6
6
  Requires-Dist: protobuf >3
7
+ Requires-Dist: pyarrow >15
7
8
  License-File: LICENSE
8
9
  Summary: Fast python conversion from protobuf to arrow using rust
9
10
  Home-Page: https://github.com/0x26res/ptars
@@ -0,0 +1,7 @@
1
+ ptars-0.0.2rc2.dist-info/METADATA,sha256=BSrX4iqdhZ8InZCooZuHCuCx-nugFar6U-WqlLdUzBM,3196
2
+ ptars-0.0.2rc2.dist-info/WHEEL,sha256=SRnG_FQQvieLA6itQS84WHKSBcd0TLWM889Dyr1qTMA,106
3
+ ptars-0.0.2rc2.dist-info/license_files/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
+ ptars/internal.py,sha256=XrEkzYCBgvw4byJcbBCpN8l9Bfh8UT0GNt6husC55P8,2332
5
+ ptars/__init__.py,sha256=jXZ06k5IZhcIXjEPkIbjtK-d4SBD2jnjFPD4XznB6xM,66
6
+ ptars/_lib.cpython-311-darwin.so,sha256=zJSBlap9lg-nn_tGwCgFZAxe-znT_FW55rKKpuGLaAk,8352176
7
+ ptars-0.0.2rc2.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- ptars-0.0.1rc1.dist-info/METADATA,sha256=E0HksJNPFg9E8UOwwPfOf5F_WVetMDDjZmKHBkdap_U,3169
2
- ptars-0.0.1rc1.dist-info/WHEEL,sha256=SRnG_FQQvieLA6itQS84WHKSBcd0TLWM889Dyr1qTMA,106
3
- ptars-0.0.1rc1.dist-info/license_files/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
- ptars/internal.py,sha256=9hl89aQF4t0E25GnQxTx8U-qetDpFAnt4AMLDv0Hu9s,1468
5
- ptars/__init__.py,sha256=jXZ06k5IZhcIXjEPkIbjtK-d4SBD2jnjFPD4XznB6xM,66
6
- ptars/_lib.cpython-311-darwin.so,sha256=Wny53T9IPdT2nuEBwvNQChHM89Bpq_RHHbP3XN7dTck,8348984
7
- ptars-0.0.1rc1.dist-info/RECORD,,