![]() Searching for a solution is how I found this question. This ConfusionMatrix class inherits a pandas.DataFrame and adds a ton of other attributes and methods that need to be recomputed unless the other matrix data can be copied over. If hasattr(parent_type, k) and hasattr(self, k) and getattr(parent_type, k) = getattr(self, k): ![]() The name of a constructor is always the same, init (). Constructors can also verify that there are enough resources for the object and perform any other start-up task you can think of. Parent_type = super(ConfusionMatrix, self) Python relies on the constructor to perform tasks such as initializing (assigning values to) any instance variables that the object will need when it starts. def construct_copy( self, other, *args, **kwargs): # construct a parent DataFrame instance Pass # df is just data, so continue with normal constructor here. ![]() Return except (AssertionError, AttributeError, ValueError): # Check if `df` looks like a `ConfusionMatrix` # Could check `isinstance(df, ConfusionMatrix)` # But might miss some "ConfusionMatrix-elligible" `DataFrame`s assert((df.columns = df.index). Destructor: Destructor in Python is called when an object gets destroyed. The task of constructors is to initialize and assign values to the data members of the class when an object of the class is created. The constructor is called whenever an instance of that class is created, in. Constructor: A constructor in Python is a special type of method which is used to initialize the instance members of the class. Building on train of thought and addressing need (I think) to do the data copy for all attributes within the constructor: class ConfusionMatrix( pd.DataFrame): def _init_( self, df, *args, **kwargs): try: A constructor is a function tied to a specific class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |