Skip to content

Commit 47ec090

Browse files
committed
add switch_dataloader_fn
1 parent fc0a7e9 commit 47ec090

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

pina/_src/condition/condition_base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, **kwargs):
3434
"""
3535
super().__init__()
3636
self.data = self.store_data(**kwargs)
37+
self.has_custom_dataloader_fn = False
3738

3839
@property
3940
def problem(self):
@@ -131,3 +132,17 @@ def create_dataloader(
131132
batch_size=batch_size,
132133
**kwargs,
133134
)
135+
136+
def switch_dataloader_fn(self, create_dataloader_fn):
137+
"""
138+
Decorator to switch the dataloader function for a condition.
139+
140+
:param create_dataloader_fn: The new dataloader function to use.
141+
:type create_dataloader_fn: function
142+
:return: The decorated function with the new dataloader function.
143+
:rtype: function
144+
"""
145+
# Replace the create_dataloader method of the ConditionBase class with
146+
# the new function
147+
self.has_custom_dataloader_fn = True
148+
self.create_dataloader = create_dataloader_fn

0 commit comments

Comments
 (0)