Skip to content

Commit

Permalink
Merge branch 'main' into bgv1-dev-branch.
Browse files Browse the repository at this point in the history
Includes the move of safe_pandas_concat to brainglobe-utils.
  • Loading branch information
willGraham01 committed Nov 1, 2023
2 parents d27f93d + 4c0e2d3 commit c8ba83c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 52 deletions.
27 changes: 0 additions & 27 deletions brainreg/core/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 brainreg/core/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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"brainglobe-utils",
"fancylog",
"imio",
"brainglobe-utils>=0.2.7",
"numpy",
"scikit-image",
]
Expand Down
22 changes: 0 additions & 22 deletions tests/tests/test_unit/test_misc.py

This file was deleted.

0 comments on commit c8ba83c

Please sign in to comment.