ekaterinailin / AltaiPony

Find flares in Kepler and TESS light curves. Notebooks for quickstart inside.
https://altaipony.readthedocs.io
MIT License
26 stars 10 forks source link

Naming of the method append to concatenate or merge #46

Closed agy-why closed 4 years ago

agy-why commented 5 years ago

What needs to be created or improved?

In python naming a method append usually returns a modified version of the object, and not a modified copy. For this behavior the naming concatenate or merge is used.

Can you provide an example?

a = [1, 2, 3]
a.append(4)
print(a)
>>> [1, 2, 3, 4]

a is modified.

lc1.append(lc2)

lc1 is not modified

What is the goal / expected behaviour?

import copy

class A():

    def __init__(self, data):
        self.data = data

    def concatenate(self, other):
        '''This concatenate self.data and other.data into a new object'''
        merged = copy.deepcopy(self)
        merged.data += other.data
        return(merged)

    def append(self, other):
        '''This append other.data at the end of self.data.'''
        self.data += other.data
        return(True)
ekaterinailin commented 4 years ago

I decided not to offer the concatenation function anymore because