@@ -1983,10 +1983,16 @@ def dtype(self):
19831983 ):
19841984 # Use the cached dtype
19851985 return self ._dtype_
1986+
1987+ # Return None if there is a missing operand (e.g. a removed file on disk)
1988+ if any (v is None for v in self .operands .values ()):
1989+ return None
1990+
19861991 operands = {
19871992 key : np .ones (np .ones (len (value .shape ), dtype = int ), dtype = value .dtype )
19881993 for key , value in self .operands .items ()
19891994 }
1995+
19901996 if "contains" in self .expression :
19911997 _out = ne_evaluate (self .expression , local_dict = operands )
19921998 else :
@@ -2019,6 +2025,11 @@ def shape(self):
20192025 ):
20202026 # Use the cached shape
20212027 return self ._shape_
2028+
2029+ # Return None if there is a missing operand (e.g. a removed file on disk)
2030+ if any (v is None for v in self .operands .values ()):
2031+ return None
2032+
20222033 # Operands shape can change, so we always need to recompute this
20232034 _shape , chunks , blocks , fast_path = validate_inputs (self .operands , getattr (self , "_out" , None ))
20242035 if fast_path :
@@ -3099,11 +3110,16 @@ def _open_lazyarray(array):
30993110 raise TypeError ("Error when retrieving the operands" )
31003111
31013112 expr = lazyarray ["expression" ]
3102- new_expr = LazyExpr ._new_expr (expr , operands_dict , guess = True , out = None , where = None )
3103- # Make the array info available for the user (only available when opened from disk)
3104- new_expr .array = array
3105- # We want to expose schunk too, so that .info() can be used on the LazyArray
3106- new_expr .schunk = array .schunk
3113+ try :
3114+ new_expr = LazyExpr ._new_expr (expr , operands_dict , guess = True , out = None , where = None )
3115+ # Make the array info available for the user (only available when opened from disk)
3116+ new_expr .array = array
3117+ # We want to expose schunk too, so that .info() can be used on the LazyArray
3118+ new_expr .schunk = array .schunk
3119+ except RuntimeError :
3120+ # Something unexpected happened. Avoid guessing and return something that
3121+ # can be introspected.
3122+ new_expr = LazyExpr ._new_expr (expr , operands_dict , guess = False , out = None , where = None )
31073123 return new_expr
31083124
31093125
0 commit comments