exa-analytics / exatomic

A unified platform for theoretical and computational chemists
https://exa-analytics.github.io/exatomic
Apache License 2.0
19 stars 12 forks source link

Failing BasisSet tests #277

Closed herbertludowieg closed 1 year ago

herbertludowieg commented 1 year ago

Describe the bug The unit tests for TestBasisSet::test_functions_by_shell and TestBasisSet::test_primitives_by_shell are failing. After some digging it seems that it might be from a difference in the data type of the index (int and 'categorical').

I noticed that there is a self.groupby in the BasisSet.functions_by_shell and BasisSet.primitives_by_shell methods. What I'm thinking is that the 'categorical' data type persists through the groupby and is causing this issue.

I propose that we add the line obj = self._revert_categories(inplace=False) in both methods and change the code in the DataFrame._revert_categories to

def _revert_categories(self, inplace=True):
    """
    Inplace conversion to categories.
    """
    if inplace:
        for column, dtype in self._categories.items():
            if column in self.columns:
                self[column] = self[column].astype(dtype)
    else:
        copy = self.copy()
        for column, dtype in copy._categories.items():
            if column in copy.columns:
                copy[column] = copy[column].astype(dtype)
        return copy

Essentially adding a kwarg so the replacement is not done inplace. I think this is a better way so that we don't have to run _revert categories and _set_categories for such a simple thing.

herbertludowieg commented 1 year ago

I tested the patch above on 3.7, 3.8, 3.9, and 3.10 with pandas version 1.5.3 for all but 3.7 which used 1.3.5. All tests pass locally.