From 254524fa38683520714962c844094d6a4769c643 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 18 May 2022 09:21:32 -0400 Subject: [PATCH 1/3] clarified sequence and iterable argument types --- python/damask/_table.py | 8 ++++---- python/damask/_vtk.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python/damask/_table.py b/python/damask/_table.py index 2d2c30c00..293f8fb1a 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -1,6 +1,6 @@ import re import copy -from typing import Union, Tuple, List +from typing import Union, Tuple, List, Iterable import pandas as pd import numpy as np @@ -14,7 +14,7 @@ class Table: def __init__(self, shapes: dict, data: np.ndarray, - comments: Union[str, list] = None): + comments: Union[str, Iterable] = None): """ New spreadsheet. @@ -434,8 +434,8 @@ class Table: def rename(self, - old: Union[str, List[str]], - new: Union[str, List[str]], + old: Union[str, Iterable[str]], + new: Union[str, Iterable[str]], info: str = None) -> 'Table': """ Rename column data. diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index 6baa16214..ccbfddd98 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -153,11 +153,11 @@ class VTK: Parameters ---------- - cells : iterable of int, len (3) + cells : sequence of int, len (3) Number of cells along each dimension. - size : iterable of float, len (3) + size : sequence of float, len (3) Physical length along each dimension. - origin : iterable of float, len (3), optional + origin : sequence of float, len (3), optional Coordinates of grid origin. Returns @@ -257,7 +257,7 @@ class VTK: Parameters ---------- - grid : iterables of floats, len (3) + grid : sequence of floats, len (3) Grid coordinates along x, y, and z directions. Returns From 164c7b4bc3fcc428d23f2b516f8ff14e35afda22 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 18 May 2022 09:31:19 -0400 Subject: [PATCH 2/3] clarified sequence of sequences argument type --- python/damask/_vtk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index ccbfddd98..17d8afa53 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -257,7 +257,7 @@ class VTK: Parameters ---------- - grid : sequence of floats, len (3) + grid : sequence of sequences of floats, len (3) Grid coordinates along x, y, and z directions. Returns From 92a4883344072c0a20e1bbcba4db7e46d7b3366b Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 19 May 2022 12:19:55 -0400 Subject: [PATCH 3/3] consistent and correct type hinting/documentation for comments --- python/damask/_grid.py | 7 ++++--- python/damask/_table.py | 4 ++-- python/damask/_vtk.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index f7acfe5aa..4e82a4180 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -50,15 +50,16 @@ class Grid: Coordinates of grid origin in meter. Defaults to [0.0,0.0,0.0]. initial_conditions : dictionary, optional Labels and values of the inital conditions at each material point. - comments : (list of) str, optional - Comments, e.g. history of operations. + comments : str or iterable of str, optional + Additional, human-readable information, e.g. history of operations. """ self.material = material self.size = size # type: ignore self.origin = origin # type: ignore self.initial_conditions = {} if initial_conditions is None else initial_conditions - self.comments = [] if comments is None else comments # type: ignore + comments_ = [comments] if isinstance(comments,str) else comments + self.comments = [] if comments_ is None else [str(c) for c in comments_] def __repr__(self) -> str: """Give short human-readable summary.""" diff --git a/python/damask/_table.py b/python/damask/_table.py index 293f8fb1a..daba4ab95 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -14,7 +14,7 @@ class Table: def __init__(self, shapes: dict, data: np.ndarray, - comments: Union[str, Iterable] = None): + comments: Union[str, Iterable[str]] = None): """ New spreadsheet. @@ -30,7 +30,7 @@ class Table: """ comments_ = [comments] if isinstance(comments,str) else comments - self.comments = [] if comments_ is None else [c for c in comments_] + self.comments = [] if comments_ is None else [str(c) for c in comments_] self.shapes = { k:(v,) if isinstance(v,(np.int64,np.int32,int)) else v for k,v in shapes.items() } self.data = pd.DataFrame(data=data) self._relabel('uniform') diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index 17d8afa53..c41470638 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -103,7 +103,7 @@ class VTK: Parameters ---------- - comments : str or list of str + comments : str or sequence of str Comments. """