Skip to content

Commit 5350b4f

Browse files
authored
Merge pull request #1173 from effigies/mnt/pandas-3
fix: Accommodate deprecations in the upcoming Pandas 3 release
2 parents fd43e7d + e7becbd commit 5350b4f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/bids/layout/tests/test_models.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sqlalchemy import create_engine
1111
from sqlalchemy.orm import sessionmaker
1212
import numpy as np
13+
import pandas as pd
1314

1415
from bids.layout.models import (BIDSFile, Entity, Tag, Base, Config,
1516
FileAssociation, BIDSImageFile, LayoutInfo)
@@ -210,12 +211,12 @@ def test_bidsdatafile_enforces_dtype(layout_synthetic):
210211
bf = layout_synthetic.get(suffix='participants', extension='tsv')[0]
211212
df = bf.get_df(enforce_dtypes=False)
212213
assert df.shape[0] == 5
213-
assert df.loc[:, 'subject_id'].dtype == int
214-
assert df.loc[:, 'subject_id'][0] == 1
214+
assert pd.api.types.is_integer_dtype(df['subject_id'])
215+
assert df.loc[0, 'subject_id'] == 1
215216
df = bf.get_df(enforce_dtypes=True)
216-
assert df.loc[:, 'subject_id'].dtype == 'O'
217-
assert df.loc[:, 'subject_id'][0] == '001'
218-
assert df.loc[:, 'subject_id'][1] == '2'
217+
assert pd.api.types.is_string_dtype(df['subject_id'])
218+
assert df.loc[0, 'subject_id'] == '001'
219+
assert df.loc[1, 'subject_id'] == '2'
219220

220221

221222
def test_bidsimagefile_get_image():

src/bids/variables/variables.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def to_dense(self, sampling_rate=None):
413413
duration = math.ceil( # Round up to nearest second
414414
round(bin_sr * self.get_duration(), 3) # Cut off at millisecond precision
415415
)
416-
ts = np.zeros(duration, dtype=self.values.dtype)
416+
ts = pd.Series(0, index=np.arange(duration), dtype=self.values.dtype)
417417

418418
onsets = np.round(self.onset * bin_sr).astype(int)
419419
durations = np.round(self.duration * bin_sr).astype(int)
@@ -446,7 +446,6 @@ def to_dense(self, sampling_rate=None):
446446
source=self.source,
447447
sampling_rate=sampling_rate)
448448

449-
450449
return dense_var
451450

452451
def _extract_entities(self):

0 commit comments

Comments
 (0)