Skip to content

Commit

Permalink
Use safe_concat function from brainglobe-utils (#148)
Browse files Browse the repository at this point in the history
* Use safe_concat function from brainglobe-utils

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove py3.8 support, since brainglobe-utils is now a hard dependency

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: willGraham01 <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2023
1 parent ab18739 commit 4c0e2d3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 72 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ jobs:
python-version: "3.10"
- os: windows-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "3.8"

steps:
- name: Cache atlases
Expand Down
27 changes: 8 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "brainreg"
description = "Automated 3D brain registration"
readme = "README.md"
authors = [
{name = "Adam Tyson, Charly Rousseau", email = "[email protected]"},
{ name = "Adam Tyson, Charly Rousseau", email = "[email protected]" },
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -16,13 +16,13 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"bg-atlasapi",
"bg-space",
"fancylog",
"imio",
"brainglobe-utils",
"brainglobe-utils>=0.2.7",
"numpy",
"scikit-image",
]
Expand All @@ -35,22 +35,13 @@ napari = [
"brainreg-segment>=0.0.2",
"napari[pyside2]",
]
dev = [
"black",
"pre-commit",
"pytest",
"pytest-cov",
]
dev = ["black", "pre-commit", "pytest", "pytest-cov"]

[project.scripts]
brainreg = "brainreg.cli:main"

[build-system]
requires = [
"setuptools>=45",
"wheel",
"setuptools_scm[toml]>=6.2",
]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
Expand All @@ -72,11 +63,9 @@ filterwarnings = [
"ignore:`np.uint0` is a deprecated alias for `np.uintp`",
"ignore:`np.void0` is a deprecated alias for `np.void`",
"ignore:`np.bytes0` is a deprecated alias for `np.bytes_`",
"ignore:`np.str0` is a deprecated alias for `np.str_`"
]
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"ignore:`np.str0` is a deprecated alias for `np.str_`",
]
markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')"]

[tool.black]
target-version = ['py38', 'py39', 'py310', 'py311']
Expand All @@ -85,6 +74,6 @@ line-length = 79

[tool.ruff]
line-length = 79
exclude = ["__init__.py","build",".eggs"]
exclude = ["__init__.py", "build", ".eggs"]
select = ["I", "E", "F"]
fix = true
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
21 changes: 0 additions & 21 deletions tests/tests/test_unit/test_misc.py

This file was deleted.

0 comments on commit 4c0e2d3

Please sign in to comment.