Skip to content

Commit

Permalink
Merge pull request #41 from david-salac/Value-only-sheets
Browse files Browse the repository at this point in the history
Value only sheets
  • Loading branch information
david-salac authored Mar 15, 2021
2 parents 2d5d02b + 9fdbe12 commit fad89e5
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 62 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ on the beginning of the sheet as a offset for labels.
added on the beginning of the sheet as a offset for labels.
8. `warning_logger (Callable[[str], None]])`: Function that logs the warnings
(or `None` if logging should be skipped).
9. `values_only (bool)`: If set to True, only values are computed and
nothing can be exported (makes script run faster)

First two are the most important because they define labels for the columns
and rows indices. The warnings mention above occurs when the slices are
Expand Down
2 changes: 1 addition & 1 deletion portable_spreadsheet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
from .grammar_utils import GrammarUtils # noqa
from .skipped_label import SkippedLabel # noqa

__version__ = "2.1.8"
__version__ = "2.1.9"
__status__ = "Production"
223 changes: 182 additions & 41 deletions portable_spreadsheet/cell.py

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions portable_spreadsheet/cell_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,18 @@ def __init__(self,
# assign the help texts
self.rows_help_text: List[str] = copy.deepcopy(rows_help_text)
self.columns_help_text: List[str] = copy.deepcopy(columns_help_text)
# This set the sheet to store only values and not to constructs words
# it is used by Cell class
self.values_only: bool = False

@property
def supported_languages(self) -> List[str]:
"""Returns all languages supported by the indicies.
Returns:
List[str]: All languages supported by this indices.
"""
return [].extend(self.user_defined_languages, system_languages)

@property
def shape(self) -> Tuple[int]:
def shape(self) -> Tuple[int, int]:
"""Return the shape of the object in the NumPy logic.
Returns:
Tuple[int]: Number of rows, Number of columns
Tuple[int, int]: Number of rows, Number of columns
"""
language = list(self.columns.keys())[0]
return len(self.rows[language]), len(self.columns[language])
return self.number_of_rows, self.number_of_columns

@property
def languages(self) -> List[str]:
Expand Down
7 changes: 6 additions & 1 deletion portable_spreadsheet/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def create_new_sheet(
columns_help_text: List[str] = None,
excel_append_row_labels: bool = True,
excel_append_column_labels: bool = True,
warning_logger: Optional[Callable[[str], None]] = None
warning_logger: Optional[Callable[[str], None]] = None,
values_only: bool = False
) -> 'Sheet':
"""Direct way of creating instance.
Expand All @@ -104,6 +105,9 @@ def create_new_sheet(
on the beginning of the sheet as a offset for labels.
warning_logger (Optional[Callable[[str], None]]): Function that
logs the warnings (or None if skipped).
values_only (bool): Set the sheet to store only values and not to
constructs words - makes computation faster but disable all
export functionality
Returns:
Sheet: New instance of spreadsheet.
Expand All @@ -120,6 +124,7 @@ def create_new_sheet(
excel_append_column_labels=excel_append_column_labels,
warning_logger=warning_logger
)
class_index.values_only = values_only
return cls(class_index, warning_logger, name)

def _initialise_array(self) -> T_sheet:
Expand Down
5 changes: 2 additions & 3 deletions portable_spreadsheet/sheet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def brackets(body: Cell) -> Cell:
"""
return Cell.brackets(body)

@staticmethod
def cross_reference(target: Cell, sheet: 'Sheet') -> Cell:
def cross_reference(self, target: Cell, sheet: 'Sheet') -> Cell:
"""Cross reference to other sheet in the workbook.
Args:
Expand All @@ -188,7 +187,7 @@ def cross_reference(target: Cell, sheet: 'Sheet') -> Cell:
Return:
Cell: reference to the different location.
"""
return Cell.cross_reference(target, sheet)
return Cell.cross_reference(target, sheet, self.spreadsheet)

@staticmethod
def ln(value: Cell) -> Cell:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="portable-spreadsheet",
version="2.1.8",
version="2.1.9",
author="David Salac",
author_email="info@davidsalac.eu",
description="A simple spreadsheet that keeps tracks of each operation of each cell in defined languages. Logic allows exporting sheets to Excel files (and see how each cell is computed), to the JSON strings with a description of computation of each cell (e. g. in the native language). Other formats, like HTML, CSV and Markdown (MD), are also implemented (user can define own format). It also allows reconstructing behaviours in native Python with NumPy.", # noqa
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cell_word_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ def test_cross_reference(self):
3, 3
)
with self.assertRaises(ValueError):
Cell.cross_reference(self.u_operand, sheet)
u_reference = Cell.cross_reference(self.a_operand, sheet)
Cell.cross_reference(self.u_operand, sheet, sheet)
u_reference = Cell.cross_reference(self.a_operand, sheet, sheet)
u_ref_word = u_reference.parse
self.assertEqual(u_ref_word['excel'], "=" + "'Results'!F5")
self.assertEqual(u_ref_word['python_numpy'], "Results.values[3,4]")
Expand Down

0 comments on commit fad89e5

Please sign in to comment.