MDAnalysis / GridDataFormats

GridDataFormats is a pure Python library to handle data on a regular grid using commonly used file formats in molecular simulations.
https://mdanalysis.org/GridDataFormats
GNU Lesser General Public License v3.0
29 stars 18 forks source link

multiple Grid __init__ calls can break extended Grid classes #73

Closed eloyfelix closed 4 years ago

eloyfelix commented 4 years ago

Grid __init__ is called twice if the grid is loaded from a file. AFAIK this is not a good practice and can break extended Grid classes. Example below:

from gridData import Grid

class NewGrid(Grid):

    def __init__(self, new_stuff=None, grid=None, edges=None, origin=None, delta=None,
                 metadata=None, interpolation_spline_order=3, file_format=None):

        if new_stuff:
            print('loading new stuff')
        else:
            print('crashing because new_stuff is None')

        super().__init__(grid, edges, origin, delta,
                         metadata, interpolation_spline_order, file_format)

aa = NewGrid('new_stuff', 'test_grid.pkl')

loading new stuff
crashing because new_stuff is None

Sending a PR to fix it soon.