@@ -134,7 +134,7 @@ class MuData:
134134
135135 def __init__ (
136136 self ,
137- data : Union [AnnData , Mapping [str , AnnData ], "MuData" ] = None ,
137+ data : Union [AnnData , Mapping [str , AnnData ], "MuData" ] | None = None ,
138138 feature_types_names : dict | None = {
139139 "Gene Expression" : "rna" ,
140140 "Peaks" : "atac" ,
@@ -150,6 +150,7 @@ def __init__(
150150 data
151151 AnnData object or dictionary with AnnData objects as values.
152152 If a dictionary is passed, the keys will be used as modality names.
153+ If None, creates an empty MuData object.
153154 feature_types_names
154155 Dictionary to map feature types encoded in data.var["feature_types"] to modality names.
155156 Only relevant when data is an AnnData object.
@@ -168,7 +169,10 @@ def __init__(
168169
169170 # Add all modalities to a MuData object
170171 self .mod = ModDict ()
171- if isinstance (data , abc .Mapping ):
172+ if data is None :
173+ # Initialize an empty MuData object
174+ pass
175+ elif isinstance (data , abc .Mapping ):
172176 for k , v in data .items ():
173177 self .mod [k ] = v
174178 elif isinstance (data , AnnData ):
@@ -231,10 +235,10 @@ def __init__(
231235
232236 return
233237
234- # Initialise global observations
238+ # Initialize global observations
235239 self ._obs = pd .DataFrame ()
236240
237- # Initialise global variables
241+ # Initialize global variables
238242 self ._var = pd .DataFrame ()
239243
240244 # Make obs map for each modality
@@ -249,6 +253,7 @@ def __init__(
249253
250254 self ._axis = 0
251255
256+ # Only call update() if there are modalities
252257 self .update ()
253258
254259 def _init_common (self ):
@@ -1740,8 +1745,9 @@ def update(self):
17401745
17411746 NOTE: From v0.4, it will not pull columns from modalities by default.
17421747 """
1743- self .update_var ()
1744- self .update_obs ()
1748+ if len (self .mod ) > 0 :
1749+ self .update_var ()
1750+ self .update_obs ()
17451751
17461752 @property
17471753 def axis (self ) -> int :
0 commit comments