Skip to content

Commit

Permalink
fix: Pandas deprecations (#906)
Browse files Browse the repository at this point in the history
* chore(tox): Add UV_EXTRA_INDEX_URL for pre-releases

* fix: Copy correlation values before zeroing diagonal

* fix: Pandas deprecation

* chore(tox): Pass environment variables

* chore(ci): Enable Python 3.13 tests

* chore: Disable 3.13. runs until traits is figured out
  • Loading branch information
effigies authored Nov 22, 2024
1 parent 2e5dcb5 commit 4984e53
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"] #, "3.13"]
dependencies: [latest, pre]
include:
- python-version: "3.9"
Expand Down
11 changes: 4 additions & 7 deletions niworkflows/interfaces/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ class AddTSVHeader(SimpleInterface):
>>> addheader.inputs.in_file = 'data.tsv'
>>> addheader.inputs.columns = ['a', 'b', 'c', 'd', 'e']
>>> res = addheader.run()
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
... index_col=None)
>>> df = pd.read_csv(res.outputs.out_file, sep='\s+', index_col=None)
>>> df.columns.ravel().tolist()
['a', 'b', 'c', 'd', 'e']
Expand Down Expand Up @@ -311,7 +310,7 @@ class JoinTSVColumns(SimpleInterface):
>>> join.inputs.in_file = 'data.tsv'
>>> join.inputs.join_file = 'add.tsv'
>>> res = join.run()
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
>>> df = pd.read_csv(res.outputs.out_file, sep='\s+',
... index_col=None, dtype=float, header=None)
>>> df.columns.ravel().tolist() == list(range(5))
True
Expand All @@ -328,8 +327,7 @@ class JoinTSVColumns(SimpleInterface):
>>> res = join.run()
>>> res.outputs.out_file # doctest: +ELLIPSIS
'...data_joined.tsv'
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
... index_col=None)
>>> df = pd.read_csv(res.outputs.out_file, sep='\s+', index_col=None)
>>> df.columns.ravel().tolist()
['a', 'b', 'c', 'd', 'e']
Expand All @@ -342,8 +340,7 @@ class JoinTSVColumns(SimpleInterface):
>>> join.inputs.side = 'left'
>>> join.inputs.columns = ['a', 'b', 'c', 'd', 'e']
>>> res = join.run()
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
... index_col=None)
>>> df = pd.read_csv(res.outputs.out_file, sep='\s+', index_col=None)
>>> df.columns.ravel().tolist()
['a', 'b', 'c', 'd', 'e']
Expand Down
6 changes: 5 additions & 1 deletion niworkflows/viz/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,11 @@ def confounds_correlation_plot(
gs_descending = gs_descending[:max_dim]
features = [p for p in corr.columns if p in gs_descending]
corr = corr.loc[features, features]
np.fill_diagonal(corr.values, 0)

# Modifying in-place is no longer supported
corr_vals = corr.to_numpy(copy=True)
np.fill_diagonal(corr_vals, 0)
corr.iloc[:, :] = corr_vals

if figure is None:
plt.figure(figsize=(15, 5))
Expand Down
19 changes: 18 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python =
3.10: py310
3.11: py311
3.12: py312
3.13: py313

[gh-actions:env]
DEPENDS =
Expand All @@ -27,6 +28,20 @@ labels = test
pip_pre =
pre: true
pass_env =
TEMPLATEFLOW_HOME
# Freesurfer variables searched for
FREESURFER_HOME
SUBJECTS_DIR
FS_LICENSE
# CI variables
TEST_DATA_HOME
TEST_OUTPUT_DIR
TEST_WORK_DIR
FMRIPREP_REGRESSION_SOURCE
CACHED_WORK_DIRECTORY
# CircleCI-specific
CIRCLE_NPROCS
SAVE_CIRCLE_ARTIFACTS
# getpass.getuser() sources for Windows:
LOGNAME
USER
Expand All @@ -39,9 +54,12 @@ pass_env =
CLICOLOR
CLICOLOR_FORCE
PYTHON_GIL
deps =
py313: traits @ git+https://github.com/enthought/traits.git@10954eb
extras = tests
setenv =
pre: PIP_EXTRA_INDEX_URL=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
pre: UV_EXTRA_INDEX_URL=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
uv_resolution =
min: lowest-direct

Expand Down Expand Up @@ -91,7 +109,6 @@ set_env =
# https://github.com/pypa/pip/issues/11684
# https://github.com/pypa/pip/issues/12243
strict: PYTHONWARNINGS=error,once:pkg_resources is deprecated as an API.:DeprecationWarning:pip._internal.metadata.importlib._envs,once:Unimplemented abstract methods {'locate_file'}:DeprecationWarning:pip._internal.metadata.importlib._dists
commands_pre =
commands =
python -m build
python -m twine check dist/*
Expand Down

0 comments on commit 4984e53

Please sign in to comment.