Skip to content

Commit b7f2b07

Browse files
committed
fix: comments
1 parent 37b522d commit b7f2b07

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

gokart/task.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,7 @@ def make_target(self, relative_file_path: str | None = None, use_unique_id: bool
236236
file_path=file_path, unique_id=unique_id, processor=processor, task_lock_params=task_lock_params, store_index_in_feather=self.store_index_in_feather
237237
)
238238

239-
def _create_processor_for_dataframe_type(self, file_path: str) -> FileProcessor | None:
240-
"""
241-
Create a file processor with appropriate return_type based on task's type parameter.
242-
243-
Args:
244-
file_path: Path to the file
245-
246-
Returns:
247-
FileProcessor with return_type set, or None to use default processor
248-
"""
239+
def _create_processor_for_dataframe_type(self, file_path: str) -> FileProcessor:
249240
df_type = get_dataframe_type_from_task(self)
250241
return make_file_processor(file_path, dataframe_type=df_type, store_index_in_feather=self.store_index_in_feather)
251242

gokart/utils.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ def get_dataframe_type_from_task(task: Any) -> Literal['pandas', 'polars', 'pola
118118
"""
119119
task_class = task if isinstance(task, type) else task.__class__
120120

121-
if not hasattr(task_class, '__orig_bases__'):
122-
return 'pandas'
123-
124-
for base in task_class.__orig_bases__:
125-
origin = get_origin(base)
126-
# Check if this is a TaskOnKart subclass
127-
if origin and hasattr(origin, '__name__') and origin.__name__ == 'TaskOnKart':
128-
args = get_args(base)
129-
if args:
121+
# Walk the MRO to find TaskOnKart[...] even when defined on a parent class
122+
mro = task_class.mro() if hasattr(task_class, 'mro') else [task_class]
123+
124+
for cls in mro:
125+
for base in getattr(cls, '__orig_bases__', ()):
126+
origin = get_origin(base)
127+
if origin and hasattr(origin, '__name__') and origin.__name__ == 'TaskOnKart':
128+
args = get_args(base)
129+
if not args:
130+
continue
130131
df_type = args[0]
131132
module = getattr(df_type, '__module__', '')
132133

test/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,21 @@ class _DerivedLazyTask(_BaseLazyTask):
168168

169169
task = _DerivedLazyTask()
170170
self.assertEqual(get_dataframe_type_from_task(task), 'polars-lazy')
171+
172+
@pytest.mark.skipif(not HAS_POLARS, reason='polars not installed')
173+
def test_nested_inheritance_polars_with_mixin(self):
174+
"""Derived class with multiple bases should still detect polars through MRO."""
175+
176+
class _Mixin:
177+
pass
178+
179+
class _BasePolarsTask(TaskOnKart[pl.DataFrame]):
180+
pass
181+
182+
# Multiple inheritance gives _DerivedTask its own __orig_bases__,
183+
# which shadows the parent's and doesn't contain TaskOnKart[...].
184+
class _DerivedTask(_BasePolarsTask, _Mixin):
185+
pass
186+
187+
task = _DerivedTask()
188+
self.assertEqual(get_dataframe_type_from_task(task), 'polars')

0 commit comments

Comments
 (0)