Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Dec 19, 2023
1 parent b1179bb commit 884883c
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/omnipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
__version__ = '0.12.2'

import importlib
import os
import sys
from typing import Optional

from omnipy.data.dataset import Dataset
from omnipy.data.model import Model
Expand Down Expand Up @@ -137,6 +134,7 @@
'convert_dataset_csv_to_pandas',
'convert_dataset_pandas_to_csv',
'convert_dataset_list_of_dicts_to_pandas',
'extract_columns_as_files',
'decode_bytes',
'modify_all_lines',
'modify_datafile_contents',
Expand Down
2 changes: 1 addition & 1 deletion src/omnipy/api/protocols/public/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
local: IsEngine | None = None, # noqa
prefect: IsEngine | None = None, # noqa
registry: IsRunStateRegistry | None = None, # noqa
serializers: IsSerializerRegistry | None = None,
serializers: IsSerializerRegistry | None = None, # noqa
root_log: IsRootLogObjects | None = None, # noqa
*args: object,
**kwargs: object) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/omnipy/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def __repr__(self):
print(get_calling_module_name())
if get_calling_module_name() in INTERACTIVE_MODULES:
_waiting_for_terminal_repr(True)
return _table_repr(self)
return self._table_repr()
return self._trad_repr()

def _trad_repr(self) -> str:
Expand All @@ -443,7 +443,7 @@ def _table_repr(self) -> str:
humanize.naturalsize(objsize.get_deep_size(v)))
for i, (k, v) in enumerate(self.items())),
('#', 'Data file name', 'Type', 'Length', 'Size (in memory)'),
tablefmt="rounded_outline",
tablefmt='rounded_outline',
)
_waiting_for_terminal_repr(False)
return ret
Expand Down
4 changes: 2 additions & 2 deletions src/omnipy/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def _table_repr(self) -> str:
bottom_structure),
),
maxcolwidths=[header_column_width, data_column_width],
tablefmt="rounded_grid",
tablefmt='rounded_grid',
)
else:
out = tabulate(
Expand All @@ -696,7 +696,7 @@ def _table_repr(self) -> str:
os.linesep.join(new_structure_lines)),
),
maxcolwidths=[header_column_width, data_column_width],
tablefmt="rounded_grid",
tablefmt='rounded_grid',
)

_waiting_for_terminal_repr(False)
Expand Down
25 changes: 12 additions & 13 deletions src/omnipy/data/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,17 @@ def load_from_tar_file_path_based_on_dataset_cls(self,
else:
log = print

with tarfile.open(tar_file_path, 'r:gz') as tarfile_obj:
serializers = self.detect_tar_file_serializers_from_dataset_cls(to_dataset)
if len(serializers) == 0:
log(f'No serializer for Dataset with type "{type(to_dataset)}" can be '
f'determined. Aborting load.')
else:
for serializer in serializers:
log(f'Reading dataset from a gzipped tarpack at'
f' "{os.path.abspath(tar_file_path)}" with serializer type: '
f'"{type(serializer)}"')
serializers = self.detect_tar_file_serializers_from_dataset_cls(to_dataset)
if len(serializers) == 0:
log(f'No serializer for Dataset with type "{type(to_dataset)}" can be '
f'determined. Aborting load.')
else:
for serializer in serializers:
log(f'Reading dataset from a gzipped tarpack at'
f' "{os.path.abspath(tar_file_path)}" with serializer type: '
f'"{type(serializer)}"')

with open(tar_file_path, 'rb') as tarfile_binary:
out_dataset = serializer.deserialize(tarfile_binary.read(), any)
with open(tar_file_path, 'rb') as tarfile_binary:
out_dataset = serializer.deserialize(tarfile_binary.read(), any)

return out_dataset
return out_dataset
1 change: 0 additions & 1 deletion src/omnipy/modules/json/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import IO, Type

from omnipy.data.dataset import Dataset
from omnipy.data.serializer import TarFileSerializer

from ...api.protocols.public.data import IsDataset
Expand Down
3 changes: 2 additions & 1 deletion src/omnipy/modules/raw/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def decode_bytes(data: bytes, encoding: str | None = None) -> str:
detector = UniversalDetector()
for line in data.splitlines():
detector.feed(line)
if detector.done: break
if detector.done:
break
detector.close()
result = detector.result

Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_get_items_with_tuple_or_list() -> None:
== dataset['data_file_1',] == dataset[('data_file_1',)] == dataset[['data_file_1']] \
== Dataset[Model[int]](data_file_1=123)
assert dataset[0, 2] == dataset[(0, 2)] == dataset[[0, 2]] \
== dataset['data_file_1','data_file_3'] == dataset[('data_file_1', 'data_file_3')] \
== dataset['data_file_1', 'data_file_3'] == dataset[('data_file_1', 'data_file_3')] \
== dataset[['data_file_1', 'data_file_3']] == dataset[[0, 'data_file_3']] \
== Dataset[Model[int]](data_file_1=dataset['data_file_1'],
data_file_3=dataset['data_file_3']) \
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/raw/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class DecodeCaseInfo(NamedTuple):
for case in test_cases:
assert decode_bytes.run(
Dataset[Model[bytes]](a=case.bytes_data), encoding=case.encoding)['a'].contents == \
case.target_str
case.target_str

for case in test_cases:
assert decode_bytes.run(
Dataset[Model[bytes]](a=case.bytes_data), encoding=None)['a'].contents == \
case.target_str
case.target_str

assert decode_bytes.run(
Dataset[Model[bytes]](dict([(case.encoding, case.bytes_data) for case in test_cases])),
Expand Down
2 changes: 1 addition & 1 deletion tests/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ def inherited_parent_staticmethod() -> bool:
return True

def inherited_parent_method(self) -> bool:
return True
return True
2 changes: 1 addition & 1 deletion tests/util/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# For test_helpers::test_get_calling_module_name
def other_module_call_get_calling_module_name() -> str:
return get_calling_module_name()
return get_calling_module_name()

0 comments on commit 884883c

Please sign in to comment.