Merge branch 'empty-table-init' into development
This commit is contained in:
commit
4a3acff213
2
PRIVATE
2
PRIVATE
|
@ -1 +1 @@
|
||||||
Subproject commit cdca8ab0c14b637c18279e0ea236caa148d15e5e
|
Subproject commit a8bd47ad55125b477e6c03277ee38ce3998a66ca
|
|
@ -12,18 +12,18 @@ class Table:
|
||||||
"""Manipulate multi-dimensional spreadsheet-like data."""
|
"""Manipulate multi-dimensional spreadsheet-like data."""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
shapes: dict,
|
shapes: dict = {},
|
||||||
data: np.ndarray,
|
data: np.ndarray = None,
|
||||||
comments: Union[str, Iterable[str]] = None):
|
comments: Union[str, Iterable[str]] = None):
|
||||||
"""
|
"""
|
||||||
New spreadsheet.
|
New spreadsheet.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
shapes : dict with str:tuple pairs
|
shapes : dict with str:tuple pairs, optional
|
||||||
Shapes of the data columns.
|
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.
|
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.
|
Data. Existing column labels of a pandas.DataFrame will be replaced.
|
||||||
comments : str or iterable of str, optional
|
comments : str or iterable of str, optional
|
||||||
Additional, human-readable information.
|
Additional, human-readable information.
|
||||||
|
@ -427,7 +427,7 @@ class Table:
|
||||||
new = pd.DataFrame(data=data.reshape(-1,size),
|
new = pd.DataFrame(data=data.reshape(-1,size),
|
||||||
columns=[label]*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)
|
dup.data = pd.concat([dup.data,new],axis=1)
|
||||||
|
|
||||||
return dup
|
return dup
|
||||||
|
|
|
@ -38,6 +38,17 @@ class TestTable:
|
||||||
d = default.get('F')
|
d = default.get('F')
|
||||||
assert np.allclose(d,1.0) and d.shape[1:] == (3,3)
|
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):
|
def test_set(self,default):
|
||||||
d = default.set('F',np.zeros((5,3,3)),'set to zero').get('F')
|
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)
|
assert np.allclose(d,0.0) and d.shape[1:] == (3,3)
|
||||||
|
|
Loading…
Reference in New Issue