Skip to content

Commit a0a3dcb

Browse files
brittonsmithchrishavlin
authored andcommitted
Backport PR yt-project#5250: Convert field_info into a property so it can be created on first access.
(cherry picked from commit 82ac140)
1 parent 01d641f commit a0a3dcb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

yt/data_objects/static_output.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class Dataset(abc.ABC):
171171
field_units: dict[AnyFieldKey, Unit] | None = None
172172
derived_field_list = requires_index("derived_field_list")
173173
fields = requires_index("fields")
174+
_field_info = None
174175
conversion_factors: dict[str, float] | None = None
175176
# _instantiated represents an instantiation time (since Epoch)
176177
# the default is a place holder sentinel, falsy value
@@ -654,7 +655,24 @@ def print_stats(self):
654655
def field_list(self):
655656
return self.index.field_list
656657

658+
@property
659+
def field_info(self):
660+
if self._field_info is None:
661+
self.index
662+
return self._field_info
663+
664+
@field_info.setter
665+
def field_info(self, value):
666+
self._field_info = value
667+
657668
def create_field_info(self):
669+
# create_field_info will be called at the end of instantiating
670+
# the index object. This will trigger index creation, which will
671+
# call this function again.
672+
if self._instantiated_index is None:
673+
self.index
674+
return
675+
658676
self.field_dependencies = {}
659677
self.derived_field_list = []
660678
self.filtered_particle_types = []

0 commit comments

Comments
 (0)