-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from functools import singledispatch | ||
from typing import Any | ||
|
||
from .package_utils import is_package_installed | ||
|
||
__author__ = "jkanche" | ||
__copyright__ = "jkanche" | ||
__license__ = "MIT" | ||
|
||
|
||
@singledispatch | ||
def relaxed_combine_columns(*x: Any): | ||
"""Combine n-dimensional objects along the second dimension. | ||
Args: | ||
x: | ||
n-dimensional objects to combine. All elements of x are expected | ||
to be the same class. | ||
Returns: | ||
Combined object, typically the same type as the first entry of ``x`` | ||
""" | ||
raise NotImplementedError( | ||
"no `combine_columns` method implemented for '" | ||
+ type(x[0]).__name__ | ||
+ "' objects." | ||
) | ||
|
||
|
||
if is_package_installed("pandas") is True: | ||
from pandas import DataFrame, concat | ||
|
||
@relaxed_combine_columns.register(DataFrame) | ||
def _relaxed_combine_columns_pandas_dataframe(*x): | ||
return concat(x, axis=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from functools import singledispatch | ||
from typing import Any | ||
|
||
from .package_utils import is_package_installed | ||
|
||
__author__ = "jkanche" | ||
__copyright__ = "jkanche" | ||
__license__ = "MIT" | ||
|
||
|
||
@singledispatch | ||
def relaxed_combine_rows(*x: Any): | ||
"""Combine n-dimensional objects along their first dimension. | ||
Args: | ||
x: | ||
One or more n-dimensional objects to combine. All elements of x | ||
are expected to be the same class. | ||
Returns: | ||
Combined object, typically the same type as the first entry of ``x``. | ||
""" | ||
raise NotImplementedError( | ||
"no `combine_rows` method implemented for '" + type(x[0]).__name__ + "' objects." | ||
) | ||
|
||
|
||
if is_package_installed("pandas"): | ||
from pandas import DataFrame, concat | ||
|
||
@relaxed_combine_rows.register(DataFrame) | ||
def _relaxed_combine_rows_pandas_dataframe(*x): | ||
return concat(x, axis=0) |