pybids icon indicating copy to clipboard operation
pybids copied to clipboard

Python3.12: Test fails with ValueError

Open penguinpee opened this issue 2 years ago • 2 comments

Python 3.12 has landed in Fedora. One of the tests fails with ValueError:

=================================== FAILURES ===================================
_________ test_run_variable_collection_bad_length_to_df_all_dense_vars _________
run_coll_bad_length = <BIDSRunVariableCollection['PTval', 'RT', 'gain', 'loss', 'parametric gain', 'respcat', 'respnum', 'trial_type']>
    def test_run_variable_collection_bad_length_to_df_all_dense_vars(run_coll_bad_length):
    
        timing_cols = {'onset', 'duration'}
        entity_cols = {'subject', 'run', 'task',  'suffix', 'datatype'}
        cond_names = {'PTval', 'RT', 'gain', 'loss', 'parametric gain', 'respcat',
                      'respnum', 'trial_type'}
        md_names = {'TaskName', 'RepetitionTime', 'extension', 'SliceTiming'}
        condition = {'condition'}
        ampl = {'amplitude'}
    
        unif_coll = run_coll_bad_length.to_dense(sampling_rate=10)
    
>       df = unif_coll.to_df()
bids/variables/tests/test_collections.py:238: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
bids/variables/collections.py:625: in to_df
    return super().to_df(
bids/variables/collections.py:152: in to_df
    dfs = [v.to_df(True, True, timing=True) for v in variables]
bids/variables/variables.py:618: in to_df
    df['onset'] = self.timestamps.values.astype(float) / 1e+9
/usr/lib64/python3.12/site-packages/pandas/core/frame.py:3980: in __setitem__
    self._set_item(key, value)
/usr/lib64/python3.12/site-packages/pandas/core/frame.py:4174: in _set_item
    value = self._sanitize_column(value)
/usr/lib64/python3.12/site-packages/pandas/core/frame.py:4915: in _sanitize_column
    com.require_length_match(value, self.index)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
data = array([0.0000e+00, 1.0000e-01, 2.0000e-01, ..., 4.3206e+03, 4.3207e+03,
       4.3208e+03])
index = RangeIndex(start=0, stop=43210, step=1)
    def require_length_match(data, index: Index) -> None:
        """
        Check the length of data matches the length of the index.
        """
        if len(data) != len(index):
>           raise ValueError(
                "Length of values "
                f"({len(data)}) "
                "does not match length of index "
                f"({len(index)})"
            )
E           ValueError: Length of values (43209) does not match length of index (43210)
/usr/lib64/python3.12/site-packages/pandas/core/common.py:571: ValueError

penguinpee avatar Jul 26 '23 13:07 penguinpee

What versions of numpy and pandas? Are their test suites passing?

effigies avatar Jul 27 '23 20:07 effigies

numpy 1.24.4 pandas 1.5.3

Regarding test suits, looking at the builds of the packages, both run tests. Tests not succeeding breaks the build, requiring intervention by either fixing the tests or disabling them temporarily.

For numpy refcount related tests were disabled for Python3.12.

penguinpee avatar Jul 27 '23 21:07 penguinpee