@@ -898,11 +898,11 @@ def __repr__(self):
898
898
@classmethod
899
899
def concatenate (cls , tables , axis = 0 ):
900
900
"""
901
- Concatenate tables into a new table, either horizontally or vertically .
901
+ Concatenate tables into a new table, either vertically or horizontally .
902
902
903
- If axis=0 (horizontal concatenate), all tables must have the same domain.
903
+ If axis=0 (vertical concatenate), all tables must have the same domain.
904
904
905
- If axis=1 (vertical ),
905
+ If axis=1 (horizontal ),
906
906
- all variable names must be unique.
907
907
- ids are copied from the first table.
908
908
- weights are copied from the first table in which they are defined.
@@ -915,12 +915,28 @@ def concatenate(cls, tables, axis=0):
915
915
Returns:
916
916
table (Table)
917
917
"""
918
+ if axis not in (0 , 1 ):
919
+ raise ValueError ("invalid axis" )
920
+ if not tables :
921
+ raise ValueError ('need at least one table to concatenate' )
922
+
923
+ if len (tables ) == 1 :
924
+ return tables [0 ].copy ()
925
+
918
926
if axis == 0 :
919
- return cls ._concatenate_vertical (tables )
920
- elif axis == 1 :
921
- return cls ._concatenate_horizontal (tables )
927
+ conc = cls ._concatenate_vertical (tables )
922
928
else :
923
- raise ValueError ("invalid axis" )
929
+ conc = cls ._concatenate_horizontal (tables )
930
+
931
+ # TODO: Add attributes = {} to __init__
932
+ conc .attributes = getattr (conc , "attributes" , {})
933
+ for table in reversed (tables ):
934
+ conc .attributes .update (table .attributes )
935
+
936
+ names = [table .name for table in tables if table .name != "untitled" ]
937
+ if names :
938
+ conc .name = names [0 ]
939
+ return conc
924
940
925
941
@classmethod
926
942
def _concatenate_vertical (cls , tables ):
@@ -941,10 +957,6 @@ def merge1d(arrs):
941
957
def collect (attr ):
942
958
return [getattr (arr , attr ) for arr in tables ]
943
959
944
- if not tables :
945
- raise ValueError ('need at least one table to concatenate' )
946
- if len (tables ) == 1 :
947
- return tables [0 ].copy ()
948
960
domain = tables [0 ].domain
949
961
if any (table .domain != domain for table in tables ):
950
962
raise ValueError ('concatenated tables must have the same domain' )
@@ -957,22 +969,12 @@ def collect(attr):
957
969
merge1d (collect ("W" ))
958
970
)
959
971
conc .ids = np .hstack ([t .ids for t in tables ])
960
- names = [table .name for table in tables if table .name != "untitled" ]
961
- if names :
962
- conc .name = names [0 ]
963
- # TODO: Add attributes = {} to __init__
964
- conc .attributes = getattr (conc , "attributes" , {})
965
- for table in reversed (tables ):
966
- conc .attributes .update (table .attributes )
967
972
return conc
968
973
969
974
@classmethod
970
975
def _concatenate_horizontal (cls , tables ):
971
976
"""
972
977
"""
973
- if not tables :
974
- raise ValueError ('need at least one table to join' )
975
-
976
978
def all_of (objs , names ):
977
979
return (tuple (getattr (obj , name ) for obj in objs )
978
980
for name in names )
@@ -992,11 +994,7 @@ def stack(arrs):
992
994
993
995
parts = all_of (doms , ("attributes" , "class_vars" , "metas" ))
994
996
domain = Domain (* (tuple (chain (* lst )) for lst in parts ))
995
- table = cls .from_numpy (domain , Xs , Ys , Ms , W , ids = tables [0 ].ids )
996
- for ta in reversed (table_attrss ):
997
- table .attributes .update (ta )
998
-
999
- return table
997
+ return cls .from_numpy (domain , Xs , Ys , Ms , W , ids = tables [0 ].ids )
1000
998
1001
999
def add_column (self , variable , data , to_metas = None ):
1002
1000
"""
0 commit comments