table-stream 0.1.9__tar.gz → 0.2.0__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.
Files changed (26) hide show
  1. {table_stream-0.1.9 → table_stream-0.2.0}/PKG-INFO +1 -1
  2. {table_stream-0.1.9 → table_stream-0.2.0}/pyproject.toml +1 -1
  3. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/__init__.py +1 -1
  4. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/table.py +115 -104
  5. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream.egg-info/PKG-INFO +1 -1
  6. {table_stream-0.1.9 → table_stream-0.2.0}/README.md +0 -0
  7. {table_stream-0.1.9 → table_stream-0.2.0}/setup.cfg +0 -0
  8. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/erros.py +0 -0
  9. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/hash_map.py +0 -0
  10. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/notifier.py +0 -0
  11. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/pattner/__init__.py +0 -0
  12. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/pattner/adapter.py +0 -0
  13. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sheet/__init__.py +0 -0
  14. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sheet/check_mod.py +0 -0
  15. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sheet/load.py +0 -0
  16. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sheet/options.py +0 -0
  17. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sheet/parse.py +0 -0
  18. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sheet/save.py +0 -0
  19. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/state.py +0 -0
  20. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/sysfiles.py +0 -0
  21. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/thread.py +0 -0
  22. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream/workbook.py +0 -0
  23. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream.egg-info/SOURCES.txt +0 -0
  24. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream.egg-info/dependency_links.txt +0 -0
  25. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream.egg-info/requires.txt +0 -0
  26. {table_stream-0.1.9 → table_stream-0.2.0}/table_stream.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: table_stream
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: Tipos de dados e implementações para o uso em tabelas.
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "table_stream"
3
- version = "0.1.9"
3
+ version = "0.2.0"
4
4
  description = "Tipos de dados e implementações para o uso em tabelas."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -88,4 +88,4 @@ from .erros import (
88
88
  HeadersSizeNotIqualError,
89
89
  )
90
90
 
91
- __version__ = "0.1.9"
91
+ __version__ = "0.2.0"
@@ -6,9 +6,14 @@ from __future__ import annotations
6
6
  from abc import abstractmethod, ABC
7
7
  from table_stream.hash_map import ArrayList, HashMapDict, HashMap, HashMapDataFrame
8
8
  from table_stream.erros import (
9
- ColumnNotFoudError, RowNotExistError, EmptyRowError,
10
- ColumnNotFoundError, HeadersSizeNotIqualError, HeaderNotFoundError,
11
- TableEmptyError, ListTablesEmptyError,
9
+ ColumnNotFoudError,
10
+ RowNotExistError,
11
+ EmptyRowError,
12
+ ColumnNotFoundError,
13
+ HeadersSizeNotIqualError,
14
+ HeaderNotFoundError,
15
+ TableEmptyError,
16
+ ListTablesEmptyError,
12
17
  )
13
18
  from typing import Any, TypeVar, Callable
14
19
  import pandas as pd
@@ -20,11 +25,11 @@ TP = TypeVar("TP")
20
25
 
21
26
 
22
27
  class RowH[HEAD, T]:
23
-
28
+
24
29
  def __init__(self, index: int, map: dict[HEAD, T] | None = None) -> None:
25
- if map is None:
30
+ if map is None:
26
31
  map = dict()
27
-
32
+
28
33
  self.map: dict[HEAD, T] = map
29
34
  self.index: int = index
30
35
 
@@ -32,13 +37,13 @@ class RowH[HEAD, T]:
32
37
  default = f"{__class__.__name__}():"
33
38
  if len(self.map) == 0:
34
39
  return f"{default} Size: 0"
35
-
40
+
36
41
  _values = ArrayList()
37
42
  for k, v in self.map.items():
38
43
  _values.add(f"{k} -> {v}")
39
-
44
+
40
45
  return f"{default}\n{_values}"
41
-
46
+
42
47
  def __eq__(self, other: object) -> bool:
43
48
  if not isinstance(other, RowH):
44
49
  raise NotImplementedError()
@@ -46,30 +51,30 @@ class RowH[HEAD, T]:
46
51
 
47
52
  def __hash__(self) -> int:
48
53
  return hash(tuple(self.map.items()))
49
-
54
+
50
55
  def hash(self) -> int:
51
56
  return self.__hash__()
52
-
57
+
53
58
  def is_empty(self) -> bool:
54
59
  return self.header().empty()
55
-
60
+
56
61
  def get_first(self) -> T:
57
62
  if self.is_empty():
58
63
  raise EmptyRowError(f"Linha vazia, adicione elementos...")
59
64
  return self.get(self.header().get_first())
60
-
65
+
61
66
  def get_row_index(self) -> int:
62
67
  return self.index
63
-
64
- def get(self, head: HEAD) -> T:
68
+
69
+ def get(self, head: HEAD) -> T:
65
70
  return self.map[head]
66
-
71
+
67
72
  def set(self, head: HEAD, v: T) -> None:
68
73
  self.map[head] = v
69
-
74
+
70
75
  def header(self) -> ArrayList[HEAD]:
71
76
  return ArrayList(list(self.map.keys()))
72
-
77
+
73
78
  def values(self) -> ArrayList[T]:
74
79
  return ArrayList(list(self.map.values()))
75
80
 
@@ -84,15 +89,15 @@ class ColumnV[HEAD, T]:
84
89
  self.head: HEAD = head
85
90
 
86
91
  def __repr__(self) -> str:
87
-
92
+
88
93
  return f"{__class__.__name__}(): Head {self.head}; Size {self.size()}; Type {self.get_type()};\n{self._elements}"
89
-
90
- #---------------------------------------------------#
94
+
95
+ # ---------------------------------------------------#
91
96
  # Leitura de Dados.
92
- #---------------------------------------------------#
97
+ # ---------------------------------------------------#
93
98
  def get_type(self) -> type[T] | None:
94
99
  return None if self.is_empty() else type(self.get_first())
95
-
100
+
96
101
  def get_elements(self) -> ArrayList[T]:
97
102
  return self._elements
98
103
 
@@ -101,60 +106,62 @@ class ColumnV[HEAD, T]:
101
106
  Retorna um elemento da coluna apartir de seu índice, se o
102
107
  índice do elemento não existir, lança a exceção RowNotExistError()
103
108
  """
104
-
109
+
105
110
  if idx >= self.size():
106
- raise RowNotExistError(f"{__class__.__name__} Linha não encontrada ... {idx}")
111
+ raise RowNotExistError(
112
+ f"{__class__.__name__} Linha não encontrada ... {idx}"
113
+ )
107
114
  return self._elements.get_element_at(idx)
108
-
115
+
109
116
  def get_first(self) -> T:
110
117
  total = self.size()
111
-
118
+
112
119
  if total == 0:
113
120
  raise ValueError(f"A coluna {self.head} está vazia")
114
121
  return self._elements[0]
115
-
122
+
116
123
  def add(self, item: T) -> None:
117
- self._elements.append(item)
118
-
124
+ self._elements.append(item)
125
+
119
126
  def add_all(self, items: ArrayList[T]) -> None:
120
127
  items.for_each(self.add)
121
-
122
- #---------------------------------------------------#
128
+
129
+ # ---------------------------------------------------#
123
130
  # Inserção/Edição de dados.
124
- #---------------------------------------------------#
131
+ # ---------------------------------------------------#
125
132
  def set(self, idx: int, value: T) -> None:
126
133
  self._elements[idx] = value
127
-
134
+
128
135
  def set_elements(self, e: ArrayList[T]) -> None:
129
- self._elements = e
136
+ self._elements = e
130
137
 
131
138
  def astype[TP](self, new_type: type[TP]) -> ArrayList[TP]:
132
- new = ArrayList[TP]()
139
+ new = ArrayList[TP]()
133
140
  for e in self._elements:
134
141
  new.append(new_type(e))
135
142
  return new
136
-
143
+
137
144
  def replace_value(self, old: T, new: T) -> None:
138
- """
139
- Substitui old por new em todas as ocorrências.
140
- """
141
- list_index = self.find_all(old)
142
-
143
- if list_index.empty():
144
- return
145
-
146
- for num in list_index:
147
- self._elements.replace(num, new)
148
-
145
+ """
146
+ Substitui old por new em todas as ocorrências.
147
+ """
148
+ list_index = self.find_all(old)
149
+
150
+ if list_index.empty():
151
+ return
152
+
153
+ for num in list_index:
154
+ self._elements.replace(num, new)
155
+
149
156
  def replace_at(self, idx: int, new: T) -> None:
150
157
  self._elements.replace(idx, new)
151
-
158
+
152
159
  def merge(self, col: ColumnV) -> None:
153
160
  self.add_all(col.get_elements())
154
161
 
155
- #---------------------------------------------------#
162
+ # ---------------------------------------------------#
156
163
  # Verificação/Validação de dados.
157
- #---------------------------------------------------#
164
+ # ---------------------------------------------------#
158
165
  def is_empty(self) -> bool:
159
166
  return self._elements.empty()
160
167
 
@@ -164,37 +171,39 @@ class ColumnV[HEAD, T]:
164
171
  def contains(self, element: T) -> bool:
165
172
  return self._elements.contains(element)
166
173
 
167
- #---------------------------------------------------#
174
+ # ---------------------------------------------------#
168
175
  # Exclusão de dados.
169
- #---------------------------------------------------#
176
+ # ---------------------------------------------------#
170
177
  def remove(self, v: T) -> None:
171
178
  self._elements.remove(v)
172
-
173
- def remove_all(self, values: ArrayList[T], *, inplace: bool = False) -> ColumnV[HEAD, T]:
174
-
179
+
180
+ def remove_all(
181
+ self, values: ArrayList[T], *, inplace: bool = False
182
+ ) -> ColumnV[HEAD, T]:
183
+
175
184
  new_elements = ArrayList[T]()
176
-
185
+
177
186
  for e in self._elements:
178
187
  if not values.contains(e):
179
188
  new_elements.add(e)
180
-
189
+
181
190
  if inplace:
182
191
  self.set_elements(new_elements)
183
-
192
+
184
193
  return ColumnV(self.head, new_elements)
185
-
186
- #---------------------------------------------------#
194
+
195
+ # ---------------------------------------------------#
187
196
  # Comandos
188
- #---------------------------------------------------#
197
+ # ---------------------------------------------------#
189
198
  def for_each(self, fn: Callable[[T], None]) -> None:
190
199
  self._elements.for_each(fn)
191
200
 
192
- def apply_command(self, fn: Callable[[T], None]) -> ColumnV[HEAD, Any]:
201
+ def apply_command(self, fn: Callable[[T], None]) -> ColumnV[HEAD, Any]:
193
202
  return ColumnV(self.head, self._elements.apply_command(fn))
194
-
195
- #---------------------------------------------------#
203
+
204
+ # ---------------------------------------------------#
196
205
  # Pesquisar/Buscar informações.
197
- #---------------------------------------------------#
206
+ # ---------------------------------------------------#
198
207
  def select(self, list_index: ArrayList[int]) -> ColumnV[HEAD, T]:
199
208
  new_col = ColumnV[HEAD, T](self.head)
200
209
  list_index.for_each(lambda num: new_col.add(self.get(num)))
@@ -220,7 +229,7 @@ class ColumnV[HEAD, T]:
220
229
  return final
221
230
 
222
231
  def filter_value(self, value: T, iqual: bool = False) -> ColumnV[HEAD, T]:
223
- list_index: ArrayList[int]
232
+ list_index: ArrayList[int]
224
233
 
225
234
  if iqual:
226
235
  list_index = self.find_all(value)
@@ -239,27 +248,25 @@ class ColumnV[HEAD, T]:
239
248
  for idx in list_index:
240
249
  final_elements.append(self._elements[idx])
241
250
  return ColumnV(self.head, final_elements)
242
-
251
+
243
252
  def filter_all(self, values: ArrayList[T]) -> ColumnV[HEAD, T]:
244
253
  final = ColumnV[HEAD, T](self.head)
245
-
246
- values.for_each(
247
- lambda item: final.merge(self.filter_value(item))
248
- )
254
+
255
+ values.for_each(lambda item: final.merge(self.filter_value(item)))
249
256
  return final
250
257
 
251
258
  def drop_duplicates(self) -> ColumnV[HEAD, T]:
252
259
  final_list = ArrayList()
253
-
260
+
254
261
  for e in self._elements:
255
262
  if not final_list.contains(e):
256
263
  final_list.append(e)
257
264
  return ColumnV(self.head, final_list)
258
-
265
+
259
266
  @classmethod
260
267
  def create_from_list(cls, h: HEAD, values: list[T]) -> ColumnV:
261
268
  return cls(h, ArrayList(values))
262
-
269
+
263
270
  @classmethod
264
271
  def create_from_series(cls, h: HEAD, s: pd.Series) -> ColumnV:
265
272
  return cls(h, ArrayList(s.values.tolist()))
@@ -311,7 +318,7 @@ class Table[HEAD](ABC):
311
318
  @abstractmethod
312
319
  def set(self, col: ColumnV[HEAD, ArrayList[T]]):
313
320
  pass
314
-
321
+
315
322
  @abstractmethod
316
323
  def set_data(self, df: pd.DataFrame) -> None:
317
324
  pass
@@ -319,7 +326,7 @@ class Table[HEAD](ABC):
319
326
  @abstractmethod
320
327
  def add(self, col: ColumnV) -> None:
321
328
  """
322
- Adiciona uma coluna na tabela.
329
+ Adiciona uma coluna na tabela.
323
330
  """
324
331
  pass
325
332
 
@@ -353,13 +360,13 @@ class Table[HEAD](ABC):
353
360
  self.get(h).add(row.get(h))
354
361
  return None
355
362
 
356
- #---------------------------------------------------#
363
+ # ---------------------------------------------------#
357
364
  # Leitura de dados - READ
358
- #---------------------------------------------------#
365
+ # ---------------------------------------------------#
359
366
  @abstractmethod
360
367
  def get_data(self) -> pd.DataFrame:
361
368
  pass
362
-
369
+
363
370
  @abstractmethod
364
371
  def get(self, h: HEAD) -> ColumnV[HEAD, Any]:
365
372
  pass
@@ -405,7 +412,7 @@ class Table[HEAD](ABC):
405
412
 
406
413
  def get_last(self) -> ColumnV:
407
414
  return self.get(self.header().get_last())
408
-
415
+
409
416
  @abstractmethod
410
417
  def select_columns(self, header: list[HEAD]) -> Table:
411
418
  pass
@@ -450,9 +457,9 @@ class Table[HEAD](ABC):
450
457
  def search(self, h: HEAD, value: Any) -> Table[HEAD]:
451
458
  pass
452
459
 
453
- #---------------------------------------------------#
460
+ # ---------------------------------------------------#
454
461
  # Verificação/validação de dados
455
- #---------------------------------------------------#
462
+ # ---------------------------------------------------#
456
463
  def size(self) -> int:
457
464
  if self.empty():
458
465
  return 0
@@ -471,20 +478,20 @@ class Table[HEAD](ABC):
471
478
  def empty(self) -> bool:
472
479
  pass
473
480
 
474
- #---------------------------------------------------#
481
+ # ---------------------------------------------------#
475
482
  # Exclusão de dados - DELETE
476
- #---------------------------------------------------#
483
+ # ---------------------------------------------------#
477
484
  @abstractmethod
478
485
  def clear(self) -> None:
479
486
  pass
480
-
487
+
481
488
  @abstractmethod
482
489
  def remove_null(self, header: HEAD) -> Table:
483
490
  pass
484
491
 
485
- #---------------------------------------------------#
492
+ # ---------------------------------------------------#
486
493
  # Conversão de dados
487
- #---------------------------------------------------#
494
+ # ---------------------------------------------------#
488
495
  def to_string(self, h: HEAD) -> str:
489
496
  return " ".join(self.get(h).astype(str))
490
497
 
@@ -547,10 +554,10 @@ class TableData[HEAD](Table):
547
554
  # ---------------------------------------------------------- #
548
555
  # Leitura de dados - READ
549
556
  # ---------------------------------------------------------- #
550
-
557
+
551
558
  def get_data(self) -> pd.DataFrame:
552
559
  return self._table_data
553
-
560
+
554
561
  def get_row_at(self, idx: int) -> RowH[HEAD, Any]:
555
562
  if self.empty():
556
563
  raise TableEmptyError("A tabela está vazia")
@@ -565,7 +572,7 @@ class TableData[HEAD](Table):
565
572
  return TableData._object_index(self._table_data.columns)
566
573
 
567
574
  def header(self) -> ArrayList[HEAD]:
568
- return ArrayList(self._table_data.columns.tolist()) # type: ignore > não falha apartir do pandas 3.x
575
+ return ArrayList(self._table_data.columns.tolist()) # type: ignore > não falha apartir do pandas 3.x
569
576
 
570
577
  def select_columns(self, header: list[HEAD]) -> TableData:
571
578
  current = self.header()
@@ -573,9 +580,7 @@ class TableData[HEAD](Table):
573
580
  if not current.contains(h):
574
581
  raise ColumnNotFoundError(f"Coluna não encontrada: {h}")
575
582
 
576
- return TableData(
577
- self._table_data[list(header)].copy()
578
- )
583
+ return TableData(self._table_data[list(header)].copy())
579
584
 
580
585
  def get(self, h: HEAD) -> ColumnV[HEAD, Any]:
581
586
  """
@@ -592,7 +597,7 @@ class TableData[HEAD](Table):
592
597
  # ---------------------------------------------------------- #
593
598
  def add_row(self, row: RowH[HEAD, Any]) -> None:
594
599
  """
595
- Adiciona uma linha a tabela se a linha não estiver vazia.
600
+ Adiciona uma linha a tabela se a linha não estiver vazia.
596
601
  """
597
602
  if row.is_empty():
598
603
  return None
@@ -650,7 +655,7 @@ class TableData[HEAD](Table):
650
655
 
651
656
  def add(self, col: ColumnV) -> None:
652
657
  """
653
- Faz o mesmo que .set()
658
+ Faz o mesmo que .set()
654
659
  """
655
660
  self.set(col)
656
661
 
@@ -678,7 +683,7 @@ class TableData[HEAD](Table):
678
683
  )
679
684
  self._table_data[col.head] = values
680
685
  self._table_data.columns = self.get_data_columns()
681
-
686
+
682
687
  def set_data(self, df: pd.DataFrame) -> None:
683
688
  self._table_data = df
684
689
 
@@ -704,13 +709,14 @@ class TableData[HEAD](Table):
704
709
  # Pesquisar/Buscar dados - SEARCH
705
710
  # ---------------------------------------------------------- #
706
711
  def search(self, h: HEAD, value: Any) -> TableData[HEAD]:
707
-
708
712
  """
709
713
  Retorna uma nova tabela apenas com as linhas onde a coluna `h` == value.
710
714
  Se nada for encontrado, retorna uma tabela com o mesmo cabeçalho e 0 linhas.
711
715
  """
712
716
  if not self.contains_header(h):
713
- raise ColumnNotFoundError(f"Coluna não encontrada: {h}")
717
+ raise ColumnNotFoundError(
718
+ f"Coluna não encontrada: {h}\nColunas disponiveis -> {self.header()}"
719
+ )
714
720
 
715
721
  df = self._table_data[self._table_data[h] == value].reset_index(drop=True)
716
722
  return TableData(df)
@@ -730,7 +736,7 @@ class TableData[HEAD](Table):
730
736
 
731
737
  def remove_null(self, header: HEAD) -> TableData[HEAD]:
732
738
  """
733
- Remove as linhas em que a coluna `header` seja NaN, "", "nan" ou "NaN".
739
+ Remove as linhas em que a coluna `header` seja NaN, "", "nan" ou "NaN".
734
740
  """
735
741
  if self.empty():
736
742
  raise TableEmptyError(f"A tabela está vazia e não possui a coluna {header}")
@@ -771,7 +777,10 @@ class TableData[HEAD](Table):
771
777
  def create_from_map(cls, hash_map: HashMap[HEAD, list[Any]]) -> TableData:
772
778
  return cls(hash_map.to_data_frame())
773
779
 
774
- def concat_tables(values: list[Table], *, rt_type: type[TableData | TableMap] = TableData) -> TableData | TableMap:
780
+
781
+ def concat_tables(
782
+ values: list[Table], *, rt_type: type[TableData | TableMap] = TableData
783
+ ) -> TableData | TableMap:
775
784
  """
776
785
  Concatenar uma lista de tabelas, se receber uma lista vazia gera a exceção ListTablesEmptyError().
777
786
  """
@@ -780,7 +789,7 @@ def concat_tables(values: list[Table], *, rt_type: type[TableData | TableMap] =
780
789
  raise ListTablesEmptyError("Não é possível concatenar uma lista vazia")
781
790
 
782
791
  final: TableData | TableMap = rt_type()
783
-
792
+
784
793
  first = values[0]
785
794
  header = first.header()
786
795
 
@@ -794,11 +803,13 @@ def concat_tables(values: list[Table], *, rt_type: type[TableData | TableMap] =
794
803
  raise TableEmptyError(f"Não é possível concatenar uma tabela vazia!")
795
804
 
796
805
  if current_table.header().size() != header.size():
797
- raise HeadersSizeNotIqualError("As tabelas precisam ter colunas de tamanhos iguais para concatenar!")
806
+ raise HeadersSizeNotIqualError(
807
+ "As tabelas precisam ter colunas de tamanhos iguais para concatenar!"
808
+ )
798
809
 
799
810
  for h in header:
800
811
  if not current_table.header().contains(h):
801
- raise ColumnNotFoundError(f'Coluna não encontrada: {h}')
812
+ raise ColumnNotFoundError(f"Coluna não encontrada: {h}")
802
813
 
803
814
  final.get(h).add_all(current_table.get(h).get_elements())
804
815
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: table_stream
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: Tipos de dados e implementações para o uso em tabelas.
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes