Open xiki-tempula opened 1 month ago
@jaclark5 Do you think it is possible to make the current code work with both pandas 2.2 and 2.1?
The quite annoy thing is that stable version of rdkit doesn't always support the latest version of pandas.
You shall be able to reproduce the problem with test_fep_estimators.py::TestMBAR::test_mbar
This error is likely because the columns for single lambda simulations are not tuples when calling groupby
in the preceding line. Before my PR, your code was consistent in not having a tuple at all, but then there was a future warning that the input for get_groups
needed to be a tuple, so I fixed that. Now that the input is a tuple like pandas wanted, it seems to be complaining that the tuple isn't recognized by the output of groupby
it must be in the preceding version of panadas that if a tuple was of length one it would pull the value... that's quite frustrating.
It seems to me that the solution would be to have all lambda state column headers be tuples all the time. That would take a bit of reformatting.
@jaclark5 I do agree that ave all lambda state column headers be tuples all the time would be good but that might break a lot of people's implementation as in most cases lambda would be a single float.
@xiki-tempula @orbeckst I looked at the changes to pandas.core.groupby.BaseGroupBy.get_group()
and the difference between pandas v2.2 and <v2.2 is the new addition of the following code:
keys = self.keys
level = self.level
# mypy doesn't recognize level/keys as being sized when passed to len
if (is_list_like(level) and len(level) == 1) or ( # type: ignore[arg-type]
is_list_like(keys) and len(keys) == 1 # type: ignore[arg-type]
):
# GH#25971
if isinstance(name, tuple) and len(name) == 1:
# Allow users to pass tuples of length 1 to silence warning
name = name[0]
elif not isinstance(name, tuple):
warnings.warn(
"When grouping with a length-1 list-like, "
"you will need to pass a length-1 tuple to get_group in a future "
"version of pandas. Pass `(name,)` instead of `name` to silence "
"this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
This warning is quite annoying since as soon as you given it the tuple it requests, it undoes that... it seems like heeding this warning was premature as pandas has not yet transitioned to the internal handling of groups that they envision and are seemingly laying the ground work for. It seems my PR should be removed to allow alchemlyb to function with the greatest breadth of pandas versions and it can be reintroduced or adjusted in the future when groupby
is more compatible to the requested behavior of get_group
in pandas >= v2.2
I no longer think adjusting alchemlyb to use tuples in lambda state columns will resolve the issue, since the output of u_nk.index.names[1:]
for a single lambda state will still be integer values in groupby
and not tuples like the get_group
method for pandas >= v2.2 wants.
407 won't work with pandas<2.2
Gives
For workflow.