Skip to content

Commit

Permalink
Use safe_concat function from brainglobe-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Oct 31, 2023
1 parent ab18739 commit bec29e0
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 51 deletions.
27 changes: 0 additions & 27 deletions src/brainreg/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from argparse import Namespace
from pathlib import PurePath

import pandas as pd


def get_arg_groups(args, parser):
arg_groups = {}
Expand All @@ -26,28 +24,3 @@ def serialise(obj):
def log_metadata(file_path, args):
with open(file_path, "w") as f:
json.dump(args, f, default=serialise)


def safe_pandas_concat(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame:
"""
Concatenate two DataFrames without relying on deprecated functionality
when one of the DataFrames is empty.
If df1 and df2 are non-empty, return the concatenation.
If df1 is empty and df2 is not, return a copy of df2.
If df1 is non-empty and df2 is, return a copy of df1.
If df1 and df2 are empty, return an empty DataFrame with the same column
names as df1.
:param df1: DataFrame to concatenate.
:param df2: DataFrame to concatenate.
:returns: DataFrame formed from concatenation of df1 and df2.
"""
if df1.empty and df2.empty:
return pd.DataFrame(columns=df1.columns)
elif df1.empty:
return df2.copy()
elif df2.empty:
return df1.copy()
else:
return pd.concat([df1, df2], ignore_index=True)
4 changes: 1 addition & 3 deletions src/brainreg/utils/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import imio
import numpy as np
import pandas as pd
from brainglobe_utils.pandas.misc import initialise_df

from .misc import safe_pandas_concat
from brainglobe_utils.pandas.misc import initialise_df, safe_pandas_concat


class UnknownAtlasValue(Exception):
Expand Down
1 change: 1 addition & 0 deletions tests/tests/test_integration/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import pytest

from brainreg.cli import main as brainreg_run

from .utils import check_images_same, check_volumes_equal
Expand Down
1 change: 1 addition & 0 deletions tests/tests/test_unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pytest

from brainreg.cli import main as brainreg_run
from brainreg.exceptions import LoadFileException

Expand Down
21 changes: 0 additions & 21 deletions tests/tests/test_unit/test_misc.py

This file was deleted.

0 comments on commit bec29e0

Please sign in to comment.