From b1b845cb5cb5a63fbc1b55bc4e4a2bf667ef1a05 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 18 May 2022 18:30:18 -0400 Subject: [PATCH 1/4] allow init of empty table --- python/damask/_table.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/damask/_table.py b/python/damask/_table.py index 2d2c30c00..9ce0ce811 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -12,8 +12,8 @@ class Table: """Manipulate multi-dimensional spreadsheet-like data.""" def __init__(self, - shapes: dict, - data: np.ndarray, + shapes: dict = {}, + data: np.ndarray = None, comments: Union[str, list] = None): """ New spreadsheet. @@ -405,7 +405,7 @@ class Table: new = pd.DataFrame(data=data.reshape(-1,size), columns=[label]*size, ) - new.index = dup.data.index + new.index = new.index if dup.data.index.empty else dup.data.index dup.data = pd.concat([dup.data,new],axis=1) return dup From b7d807db01f2a80ce23f3f5a9dbcd089edfb0bd5 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 25 May 2022 09:45:37 -0400 Subject: [PATCH 2/4] re-added default arguments that got lost in last commit --- python/damask/_table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/damask/_table.py b/python/damask/_table.py index dc2c6f961..78d7ddcb9 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -12,8 +12,8 @@ class Table: """Manipulate multi-dimensional spreadsheet-like data.""" def __init__(self, - shapes: dict, - data: np.ndarray, + shapes: dict = {}, + data: np.ndarray = None, comments: Union[str, Iterable[str]] = None): """ New spreadsheet. From 7082eab366038fba6e5958871afb962782f32dcf Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Fri, 8 Jul 2022 18:01:36 +0200 Subject: [PATCH 3/4] small test to demonstrate alternative Table init --- python/tests/test_Table.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/tests/test_Table.py b/python/tests/test_Table.py index e530abe58..5eb950817 100644 --- a/python/tests/test_Table.py +++ b/python/tests/test_Table.py @@ -38,6 +38,17 @@ class TestTable: d = default.get('F') assert np.allclose(d,1.0) and d.shape[1:] == (3,3) + def test_empty_init(self): + N = 3 + D = dict( + scal=np.arange(10), + vctr=np.arange(10*N).reshape((10,N)), + ) + t = Table() + for label,data in D.items(): + t = t.set(label,data) + assert np.allclose(t.get('scal').flatten()*3,t.get('vctr')[:,0]) + def test_set(self,default): d = default.set('F',np.zeros((5,3,3)),'set to zero').get('F') assert np.allclose(d,0.0) and d.shape[1:] == (3,3) From 7530d457a277cf55776389c88b7d6c1b8f95c932 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 15 Aug 2022 08:04:02 +0200 Subject: [PATCH 4/4] documenting new behavior --- PRIVATE | 2 +- python/damask/_table.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PRIVATE b/PRIVATE index cdca8ab0c..a8bd47ad5 160000 --- a/PRIVATE +++ b/PRIVATE @@ -1 +1 @@ -Subproject commit cdca8ab0c14b637c18279e0ea236caa148d15e5e +Subproject commit a8bd47ad55125b477e6c03277ee38ce3998a66ca diff --git a/python/damask/_table.py b/python/damask/_table.py index 6e7dcf146..356e73730 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -20,10 +20,10 @@ class Table: Parameters ---------- - shapes : dict with str:tuple pairs - Shapes of the data columns. + shapes : dict with str:tuple pairs, optional + Shapes of the data columns. Mandatory if 'data' is given. For instance, 'F':(3,3) for a deformation gradient, or 'r':(1,) for a scalar. - data : numpy.ndarray or pandas.DataFrame + data : numpy.ndarray or pandas.DataFrame, optional Data. Existing column labels of a pandas.DataFrame will be replaced. comments : str or iterable of str, optional Additional, human-readable information.