Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Replace numpy with pandas in data loaders #2829

Merged
merged 49 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1d04072
Repalce numpy with pandas
achamma723 May 7, 2021
4fae766
rebase
achamma723 Dec 16, 2021
58ff41c
[MAINT] Fix new typos found by codespell (#3101)
DimitriPapadopoulos Dec 16, 2021
68e19e5
Merge branch 'main' of https://github.com/nilearn/nilearn into test_5
achamma723 Dec 16, 2021
03e1f58
Fix pep8 + destrieux
achamma723 Dec 16, 2021
1bac472
Fix pep8
achamma723 Dec 16, 2021
382e6a4
Merge branch 'main' of https://github.com/nilearn/nilearn into test_5
achamma723 Jan 12, 2022
aeaf3ef
Merge docs
achamma723 Jan 12, 2022
24024b1
continue work (unfinished)
NicolasGensollen Jan 19, 2022
539ab52
Iter
NicolasGensollen Jan 19, 2022
c74c356
Fix test
NicolasGensollen Jan 19, 2022
0a0b98b
Fix other test
NicolasGensollen Jan 19, 2022
8ec02f9
Iter
NicolasGensollen Jan 19, 2022
93f36dd
Add warnings
NicolasGensollen Jan 20, 2022
1d0eaba
Fix PEP8
NicolasGensollen Jan 20, 2022
4264ab2
Address Jerome's reviews
NicolasGensollen Jan 24, 2022
3be0123
Fix PEP8
NicolasGensollen Jan 24, 2022
8455f92
convert to lower case in fetch_atlas_difumo
NicolasGensollen Jan 24, 2022
e558a25
[circle full] Add whatsnew.
NicolasGensollen Jan 25, 2022
ba553c2
Fix
NicolasGensollen Jan 25, 2022
0c7ff85
[circle full] remove deprecation warning from example
NicolasGensollen Jan 25, 2022
b1a86a3
Fix examples
NicolasGensollen Jan 25, 2022
41c8e7b
[ENH] Add `cbar_tick_format` to plotting functions (#2859)
NicolasGensollen Jan 17, 2022
10e1795
Rename private functions of `permuted_least_squares` to start with '_…
NicolasGensollen Jan 18, 2022
b229c9f
[MAINT] Update git protocol in CircleCI fetch step (#3124)
NicolasGensollen Jan 19, 2022
ca6746d
[MAINT] Scipy deprecation warning in RegionExtractor (#3130)
htwangtw Jan 19, 2022
0f5f07d
[MAINT] Remove deprecated `sessions` and `sample_mask` attributes of …
NicolasGensollen Jan 20, 2022
1745e44
[MAINT] Remove old workaround (#3092)
NicolasGensollen Jan 20, 2022
4668e3e
[ENH] Move FSL- and BIDS-related functions to interfaces module (#3126)
tsalo Jan 21, 2022
d0d1093
[FIX] Fix links in whats_new (#3139)
NicolasGensollen Jan 21, 2022
b42b4c0
[FIX] fixed code + added test (#3137)
bthirion Jan 24, 2022
7b4a476
[ENH] Refactor `plot_matrix` (#3001)
NicolasGensollen Jan 24, 2022
c61e7a4
[FIX] replace interpreter call (#3136)
bnavigator Jan 24, 2022
737c986
[FIX] `FirstLevelModel` signal_scaling (#3135)
NicolasGensollen Jan 24, 2022
3fcc155
[ENH] Include Hierarchical KMeans in regions.Parcellations (#2282)
thomasbazeille Jan 25, 2022
da18fdc
[DOC] Fix wrong whats_new entry (#3142)
NicolasGensollen Jan 25, 2022
d1466c2
[FIX] Fix hommel value computation (#3109)
bthirion Jan 25, 2022
3e900a9
[DOC] Refactor change logs (#3049)
NicolasGensollen Jan 26, 2022
e1657b1
Merge branch 'main' of https://github.com/nilearn/nilearn into test_5
achamma723 Jan 26, 2022
0d2bc7f
Rebase
achamma723 Jan 26, 2022
26e92ff
[circle full] fix whats_new bug
NicolasGensollen Jan 27, 2022
26de3fe
[MAINT] Bump dependencies for release `0.9.0` (#3143)
NicolasGensollen Jan 27, 2022
55db108
Jerome's review
NicolasGensollen Jan 27, 2022
fb5c56b
remove warning
NicolasGensollen Jan 27, 2022
27e00f0
[INFRA] Add tests min requirements with Matplotlib (#3144)
NicolasGensollen Jan 27, 2022
304e782
2021 -> 2022 (#3146)
NicolasGensollen Jan 27, 2022
1ba2487
Revert "[MAINT] Bump dependencies for release `0.9.0` (#3143)"
achamma723 Jan 28, 2022
f1dd5d8
Revert "[INFRA] Add tests min requirements with Matplotlib (#3144)"
achamma723 Jan 28, 2022
65fe185
Revert "2021 -> 2022 (#3146)"
achamma723 Jan 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/changes/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@ Changes
- Descriptions of datasets retrieved with fetchers from :mod:`nilearn.datasets` are
now python strings rather than `bytes`. Therefore, decoding the descriptions is no
longer necessary.
- Dataset fetchers returning a :class:`numpy.recarray` can now return a
:class:`pandas.DataFrame` instead. These fetchers now have a ``legacy_format`` optional
argument defaulting to ``True`` for backward compatibility. Users will be warned that
this parameter will default to ``False`` in release 0.11.0, making
:class:`pandas.DataFrame` the default return type instead or :class:`numpy.recarray`.
(See PR `#2829 <https://github.com/nilearn/nilearn/pull/2829>`_).
2 changes: 1 addition & 1 deletion examples/01_plotting/plot_3d_map_to_surface_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
# averaging the labels between neighboring regions. Using nearest-neighbor
# interpolation with zero radius will achieve this.

destrieux = datasets.fetch_atlas_destrieux_2009()
destrieux = datasets.fetch_atlas_destrieux_2009(legacy_format=False)

view = plotting.view_img_on_surf(
destrieux.maps,
Expand Down
3 changes: 2 additions & 1 deletion examples/01_plotting/plot_dim_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

from nilearn import datasets

localizer_dataset = datasets.fetch_localizer_button_task()
localizer_dataset = datasets.fetch_localizer_button_task(legacy_format=False)
# Contrast map of motor task
localizer_tmap_filename = localizer_dataset.tmap
# Subject specific anatomical image
localizer_anat_filename = localizer_dataset.anat

###########################################################################
# Plotting with enhancement of background image with dim=-.5
# --------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions examples/01_plotting/plot_prob_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
# Dictionaries of Functional Modes (“DiFuMo”) atlas
dim = 64
res = 2
difumo = datasets.fetch_atlas_difumo(dimension=dim,
resolution_mm=res)
difumo = datasets.fetch_atlas_difumo(
dimension=dim, resolution_mm=res, legacy_format=False
)

# Visualization
from nilearn import plotting
Expand Down
6 changes: 4 additions & 2 deletions examples/02_decoding/plot_oasis_vbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
############################################################################
# Load Oasis dataset
# -------------------
oasis_dataset = datasets.fetch_oasis_vbm(n_subjects=n_subjects)
oasis_dataset = datasets.fetch_oasis_vbm(
n_subjects=n_subjects, legacy_format=False
)
gray_matter_map_filenames = oasis_dataset.gray_matter_maps
age = oasis_dataset.ext_vars['age'].astype(float)
age = oasis_dataset.ext_vars['age'].values

# Split data into training set and test set
from sklearn.model_selection import train_test_split
Expand Down
4 changes: 3 additions & 1 deletion examples/02_decoding/plot_oasis_vbm_space_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import numpy as np
from nilearn import datasets
n_subjects = 200 # increase this number if you have more RAM on your box
dataset_files = datasets.fetch_oasis_vbm(n_subjects=n_subjects)
dataset_files = datasets.fetch_oasis_vbm(
n_subjects=n_subjects, legacy_format=False
)
age = dataset_files.ext_vars['age'].astype(float)
age = np.array(age)
gm_imgs = np.array(dataset_files.gray_matter_maps)
Expand Down
5 changes: 3 additions & 2 deletions examples/03_connectivity/plot_atlas_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def lag_correlation(time_series, lag):
# -----------------------------------------------------------------

dim = 64
difumo = datasets.fetch_atlas_difumo(dimension=dim,
resolution_mm=2)
difumo = datasets.fetch_atlas_difumo(
dimension=dim, resolution_mm=2, legacy_format=False
)

##########################################################################
# Iterate over fetched atlases to extract coordinates - probabilistic
Expand Down
4 changes: 2 additions & 2 deletions examples/03_connectivity/plot_sphere_based_connectome.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
#
# First we fetch the coordinates of the Power atlas

power = datasets.fetch_coords_power_2011()
power = datasets.fetch_coords_power_2011(legacy_format=False)
print('Power atlas comes with {0}.'.format(power.keys()))


Expand Down Expand Up @@ -306,7 +306,7 @@
# -------------------------------------------
#
# We repeat the same steps for Dosenbach's atlas.
dosenbach = datasets.fetch_coords_dosenbach_2010()
dosenbach = datasets.fetch_coords_dosenbach_2010(legacy_format=False)

coords = np.vstack((
dosenbach.rois['x'],
Expand Down
6 changes: 4 additions & 2 deletions examples/05_glm_second_level/plot_oasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
# ------------------

from nilearn import datasets
oasis_dataset = datasets.fetch_oasis_vbm(n_subjects=n_subjects)
oasis_dataset = datasets.fetch_oasis_vbm(
n_subjects=n_subjects, legacy_format=False
)
gray_matter_map_filenames = oasis_dataset.gray_matter_maps
age = oasis_dataset.ext_vars['age'].astype(float)

###############################################################################
# Sex is encoded as 'M' or 'F'. Hence, we make it a binary variable.
sex = oasis_dataset.ext_vars['mf'] == b'F'
sex = oasis_dataset.ext_vars['mf'] == 'F'

###############################################################################
# Print basic information on the dataset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
# BOLD activity estimate divided by the uncertainty about this estimate.
from nilearn.datasets import fetch_localizer_contrasts
n_subjects = 16
data = fetch_localizer_contrasts(["left vs right button press"], n_subjects,
get_tmaps=True)

data = fetch_localizer_contrasts(
["left vs right button press"], n_subjects,
get_tmaps=True, legacy_format=False
)
from nilearn import plotting

############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from nilearn import datasets
n_samples = 94
localizer_dataset = datasets.fetch_localizer_contrasts(
['left button press (auditory cue)'], n_subjects=n_samples)
['left button press (auditory cue)'],
n_subjects=n_samples, legacy_format=False
)

##############################################################################
# Let's print basic information on the dataset.
Expand All @@ -34,11 +36,13 @@
##############################################################################
# It is worth to do a auality check and remove subjects with missing values.
import numpy as np
mask_quality_check = np.where(tested_var != b'n/a')[0]
mask_quality_check = np.where(
np.logical_not(np.isnan(tested_var))
)[0]
n_samples = mask_quality_check.size
contrast_map_filenames = [localizer_dataset.cmaps[i]
for i in mask_quality_check]
tested_var = tested_var[mask_quality_check].astype(float).reshape((-1, 1))
tested_var = tested_var[mask_quality_check].values.reshape((-1, 1))
print("Actual number of subjects after quality check: %d" % n_samples)

############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
# estimate.
from nilearn.datasets import fetch_localizer_contrasts
n_subjects = 16
data = fetch_localizer_contrasts(["left vs right button press"], n_subjects,
get_tmaps=True)
data = fetch_localizer_contrasts(
["left vs right button press"], n_subjects,
get_tmaps=True, legacy_format=False
)

###########################################################################
# Display subject t_maps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
# localizer dataset.
n_subjects = 16
sample_vertical = fetch_localizer_contrasts(
["vertical checkerboard"], n_subjects, get_tmaps=True)
["vertical checkerboard"], n_subjects,
get_tmaps=True, legacy_format=False
)
sample_horizontal = fetch_localizer_contrasts(
["horizontal checkerboard"], n_subjects, get_tmaps=True)
["horizontal checkerboard"], n_subjects,
get_tmaps=True, legacy_format=False
)

# Implicitly, there is a one-to-one correspondence between the two samples:
# the first image of both samples comes from subject S1, the second from subject S2 etc.
Expand Down
3 changes: 2 additions & 1 deletion examples/05_glm_second_level/plot_thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from nilearn import datasets
n_samples = 20
localizer_dataset = datasets.fetch_localizer_calculation_task(
n_subjects=n_samples)
n_subjects=n_samples, legacy_format=False
)

#########################################################################
# Get the set of individual statstical maps (contrast estimates)
Expand Down
10 changes: 7 additions & 3 deletions examples/07_advanced/plot_localizer_mass_univariate_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@
# Load Localizer contrast
n_samples = 94
localizer_dataset = datasets.fetch_localizer_contrasts(
['left button press (auditory cue)'], n_subjects=n_samples)
['left button press (auditory cue)'],
n_subjects=n_samples, legacy_format=False
)

# print basic information on the dataset
print('First contrast nifti image (3D) is located at: %s' %
localizer_dataset.cmaps[0])

tested_var = localizer_dataset.ext_vars['pseudo']
# Quality check / Remove subjects with bad tested variate
mask_quality_check = np.where(tested_var != b'n/a')[0]
mask_quality_check = np.where(
np.logical_not(np.isnan(tested_var))
)[0]
n_samples = mask_quality_check.size
contrast_map_filenames = [localizer_dataset.cmaps[i]
for i in mask_quality_check]
tested_var = tested_var[mask_quality_check].astype(float).reshape((-1, 1))
tested_var = tested_var[mask_quality_check].values.reshape((-1, 1))
print("Actual number of subjects after quality check: %d" % n_samples)


Expand Down
3 changes: 2 additions & 1 deletion examples/07_advanced/plot_localizer_simple_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
# Load Localizer contrast
n_samples = 20
localizer_dataset = datasets.fetch_localizer_calculation_task(
n_subjects=n_samples)
n_subjects=n_samples, legacy_format=False
)
tested_var = np.ones((n_samples, 1))


Expand Down
7 changes: 7 additions & 0 deletions nilearn/_utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
ax : :class:`~matplotlib.axes.Axes`
The matplotlib axes in which the plots will be drawn."""

# Legacy_format
docdict['legacy_format'] = """
legacy_format : :obj:`bool`, optional
If set to ``True``, the fetcher will return recarrays. Otherwise,
it will return pandas dataframes.
Default=True."""

# Resume
docdict['resume'] = """
resume : :obj:`bool`, optional
Expand Down
5 changes: 0 additions & 5 deletions nilearn/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Helper functions to download NeuroImaging datasets
"""

from warnings import warn
from .struct import (fetch_icbm152_2009, load_mni152_template,
load_mni152_brain_mask, load_mni152_gm_template,
load_mni152_gm_mask, load_mni152_wm_template,
Expand Down Expand Up @@ -90,7 +89,3 @@
'fetch_fiac_first_level',
]

warn("Fetchers from the nilearn.datasets module will be "
"updated in version 0.9 to return python strings "
"instead of bytes and Pandas dataframes instead of "
"Numpy arrays.", FutureWarning)