dimanche 8 novembre 2020

Python class design for data processing

I am python beginner and I am currently learning OOP. I want to create a class which would load data from a database and then perform transformation and calculation on this data. However, I am not sure how the class should be designed. The class would have several methods and each method input is the output of the former method. However, I find this way of doing not really elegant and I feel like it is not in the spirit of OOP.

Is this a good way to design such process using OOP ? Or is it even advantageous in a such case to create a class to process the data ?

See below what I tried to do:

class Data:
      def __init__(self, arg):
          self.arg = arg (attributes necessary for the loading of data)
          
      def load_data(self):
          "load the data from somewhere and reshape it so that it can be used by method1"
          return(data)

      def method1(self, data):
          "do some transformation on the data"
          return(data1)

      def method2(self, data1):
          "do some transformation on the data1"
          return(data2)

      def method3(self, data2):
           "do some transformation on the data2"
          return(data3)

      def run(self):
           data = self.load()
           data1 = self.method1(data)
           data2 = self.method2(data1)
           data3 = self.method3(data2)
           return(data3)

Thanks in advance for your help.

Aucun commentaire:

Enregistrer un commentaire