2626import copy
2727import datetime
2828import logging
29+ import warnings
2930
3031from climada .entity .exposures import Exposures
3132from climada .entity .impact_funcs import ImpactFuncSet
@@ -83,7 +84,15 @@ def __init__(
8384 measure : Measure | None ,
8485 date : int | datetime .date | str ,
8586 ref_only : bool = False ,
87+ _from_factory : bool = False ,
8688 ) -> None :
89+ if not _from_factory :
90+ warnings .warn (
91+ "Direct instantiation of 'Snapshot' is discouraged. "
92+ "Use 'Snapshot.from_triplet()' instead." ,
93+ UserWarning ,
94+ stacklevel = 2 ,
95+ )
8796 self ._exposure = exposure if ref_only else copy .deepcopy (exposure )
8897 self ._hazard = hazard if ref_only else copy .deepcopy (hazard )
8998 self ._impfset = impfset if ref_only else copy .deepcopy (impfset )
@@ -137,6 +146,7 @@ def from_triplet(
137146 measure = None ,
138147 date = date ,
139148 ref_only = ref_only ,
149+ _from_factory = True ,
140150 )
141151
142152 @property
@@ -191,7 +201,7 @@ def _convert_to_date(date_arg) -> datetime.date:
191201
192202 raise TypeError ("date_arg must be an int, str, or datetime.date" )
193203
194- def apply_measure (self , measure : Measure , ref_only : bool = False ) -> "Snapshot" :
204+ def apply_measure (self , measure : Measure ) -> "Snapshot" :
195205 """Create a new snapshot by applying a Measure object.
196206
197207 This method creates a new `Snapshot` object by applying a measure on
@@ -216,6 +226,7 @@ def apply_measure(self, measure: Measure, ref_only: bool = False) -> "Snapshot":
216226 impfset = impfset ,
217227 date = self .date ,
218228 measure = measure ,
219- ref_only = ref_only ,
229+ ref_only = False ,
230+ _from_factory = True ,
220231 )
221232 return snap
0 commit comments