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 b42c18703..356e73730 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -12,18 +12,18 @@ 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. 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. @@ -427,7 +427,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 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)