Skip to content

Commit

Permalink
PERF-modin-project#6524: Add a 'column' shape hint for the results of…
Browse files Browse the repository at this point in the history
… 'qc.to_datetime()'

Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
  • Loading branch information
dchigarev committed Aug 31, 2023
1 parent 0fa3dda commit 9746c95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions modin/core/dataframe/algebra/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Reduce(Operator):
"""Builder class for Reduce operator."""

@classmethod
def register(cls, reduce_function, axis=None):
def register(cls, reduce_function, axis=None, shape_hint=None):
"""
Build Reduce operator that will be performed across rows/columns.
Expand All @@ -32,6 +32,8 @@ def register(cls, reduce_function, axis=None):
Source function.
axis : int, optional
Axis to apply function along.
shape_hint : {"row", "column", None}, default: None
Shape hint for the results known to be a column or a row, otherwise None.
Returns
-------
Expand All @@ -46,7 +48,8 @@ def caller(query_compiler, *args, **kwargs):
query_compiler._modin_frame.reduce(
cls.validate_axis(_axis),
lambda x: reduce_function(x, *args, **kwargs),
)
),
shape_hint=shape_hint,
)

return caller
7 changes: 5 additions & 2 deletions modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,13 @@ def to_datetime(self, *args, **kwargs):
# to_datetime has inplace side effects, see GH#3063
lambda df, *args, **kwargs: pandas.to_datetime(
df.squeeze(axis=1), *args, **kwargs
).to_frame()
).to_frame(),
shape_hint="column",
)(self, *args, **kwargs)
else:
return Reduce.register(pandas.to_datetime, axis=1)(self, *args, **kwargs)
return Reduce.register(pandas.to_datetime, axis=1, shape_hint="column")(
self, *args, **kwargs
)

# END Reduce operations

Expand Down

0 comments on commit 9746c95

Please sign in to comment.