Closed raeedcho closed 2 years ago
Nice catch, thanks! I also strongly prefer the first option of trial_data['bin_size'].values[0]
, let's go with that.
Have you found any other occurrences?
I think I've seen it from time to time in other functions, but can't think of any places off the top of my head. I'll fix and open pull requests as I find them.
Some pieces of code in the package intend to refer to the first value of a column in the trial_data DataFrame using something like:
trial_data.bin_size[0]
(example from line 99 offiring_rates.py
)This kind of reference breaks when the DataFrame doesn't have a row with index 0--which happens when you want to use another column as an index (e.g. trial_id) or when you subselect trials without resetting the index.
For generality, I think I would change these kinds of references to something like:
trial_data['bin_size'].values[0]
ortrial_data.loc[trial_data.index[0],'bin_size']
I prefer the first one most of the time for reading ease, but I think the second one avoids chained indexing, which might be preferred in cases where you're trying to assign a value to the element, rather than just accessing and viewing it.