-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Write safe concat function * Use safe concat of dataframes * Fix logic of safe concat method * pre-commit pass * Add unit test to aplease codecov overlords * Update tests/tests/test_unit/test_misc.py Co-authored-by: Alessandro Felder <[email protected]> --------- Co-authored-by: Alessandro Felder <[email protected]>
- Loading branch information
1 parent
fba5404
commit ab18739
Showing
3 changed files
with
51 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
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,21 @@ | ||
import pandas as pd | ||
from brainreg.utils.misc import safe_pandas_concat | ||
|
||
|
||
def test_safe_pandas_concat() -> None: | ||
""" | ||
Test the following: | ||
- Non-empty dataframes are concatenated as expected, | ||
- When one dataframe is empty, the other is returned, | ||
- When both dataframes are empty, an empty dataframe with | ||
the corresponding columns is returned. | ||
""" | ||
df1 = pd.DataFrame(data={"a": [1], "b": [2], "c": [3]}) | ||
df2 = pd.DataFrame(data={"a": [4], "b": [5], "c": [6]}) | ||
empty_df = pd.DataFrame(columns=["a", "b", "c"]) | ||
combined_df = pd.DataFrame(data={"a": [1, 4], "b": [2, 5], "c": [3, 6]}) | ||
|
||
assert combined_df.equals(safe_pandas_concat(df1, df2)) | ||
assert df1.equals(safe_pandas_concat(df1, empty_df)) | ||
assert df2.equals(safe_pandas_concat(empty_df, df2)) | ||
assert empty_df.equals(safe_pandas_concat(empty_df, empty_df)) |