Dangerous default value {} as argument
168 param_distributions,
169 n_iter=10,
170 scoring=None,
171 fit_params={},172 n_jobs=1,
173 iid=True,
174 refit=True,
Dangerous default value [] as argument
35 """
36 __metaclass__ = ABCMeta
37
38 def __init__(self, column, name=None, dtype=numpy.uint32, embed_scale=1, tags=[], twin=False): 39 """
40 :param column: the index name of a column in a dataframe, or a Transformer
41 :param name: an optional debugging hint, otherwise a default will be supplied
Dangerous default value [] as argument
183 Transforms a series of booleans into floating points suitable for
184 training.
185 """
186 def __init__(self, column, name=None, dtype=numpy.bool, embed_scale=1, tags=[], twin=False):187 super(Boolean, self).__init__(column, name, dtype, embed_scale, tags, twin)
188 self.missing_value = 2
189
Dangerous default value [] as argument
208
209 see also: numpy.equal
210 """
211 def __init__(self, column, other, name=None, embed_scale=1, tags=[], twin=False):212 """
213 :param column: the index name of a column in a DataFrame, or a Transformer
214 :param other: the index name of a column in a DataFrame, or a Transformer
Dangerous default value [] as argument
251class Continuous(Base):
252 """Abstract Base Class for encoders that return continuous values"""
253
254 def __init__(self, column, name=None, dtype=numpy.float16, embed_scale=1, tags=[], twin=False):255 super(Continuous, self).__init__(column, name=name, dtype=dtype, embed_scale=embed_scale, tags=tags, twin=twin)
256
257 def cardinality(self):
Dangerous default value [] as argument
260
261class Pass(Continuous):
262
263 def __init__(self, column, name=None, dtype=numpy.float16, embed_scale=1, tags=[], twin=False):264 super(Pass, self).__init__(column, name=name, dtype=dtype, embed_scale=embed_scale, tags=tags, twin=twin)
265 self.missing_value = 0
266
Dangerous default value [] as argument
283 range will be capped from 0 to 1.
284 """
285
286 def __init__(self, column, name=None, dtype=numpy.float16, embed_scale=1, tags=[], twin=False):287 super(Uniform, self).__init__(column, name=name, dtype=dtype, embed_scale=embed_scale, tags=tags, twin=twin)
288 self.__min = float('nan')
289 self.__range = float('nan')
Dangerous default value [] as argument
319 exceeds the fit range will be capped at the fit range.
320 """
321
322 def __init__(self, column, name=None, dtype=numpy.float32, embed_scale=1, tags=[], twin=False):323 super(Norm, self).__init__(column, name, dtype, embed_scale, tags=tags, twin=twin)
324 self.__min = float('nan')
325 self.__max = float('nan')
Dangerous default value [] as argument
361 bins + 1.
362 """
363
364 def __init__(self, column, name=None, bins=10, embed_scale=1, tags=[], twin=False):365 super(Discrete, self).__init__(column, name, embed_scale=embed_scale, tags=tags, twin=twin)
366 self.__norm = bins - 1
367 self.__min = float('nan')
Dangerous default value [] as argument
412 exceed previously fit max are given a unique value. Missing values are
413 also distinctly encoded.
414 """
415 def __init__(self, column, name=None, embed_scale=1, tags=[], twin=False):416 super(Enum, self).__init__(column, name, embed_scale=embed_scale, tags=tags, twin=twin)
417 self.__max = None
418 self.unfit_value = None
Dangerous default value [] as argument
457 Values the excede the upper and lower bound fit, will be placed into
458 distinct bins, as well nans.
459 """
460 def __init__(self, column, name=None, quantiles=10, embed_scale=1, tags=[], twin=False):461 """
462 :param quantiles: the number of bins
463 """
Dangerous default value [] as argument
513 the stratify column the encoded value appears with.
514 """
515
516 def __init__(self, column, name=None, minimum_occurrences=1, stratify=None, embed_scale=1, tags=[], twin=False, correlation=None):517 """
518 :param minimum_occurrences: ignore ids with less than this many occurrences
519 :param stratify: compute minimum occurrences over data column with this name
Dangerous default value [] as argument
653 """
654 PUNCTUATION_FILTER = re.compile(r'\W+\s\W+|\W+(\s|$)|(\s|^)\W+', re.UNICODE)
655
656 def __init__(self, column, name=None, sequence_length=None, minimum_occurrences=1, embed_scale=1, tags=[], twin=False):657 """
658 :param sequence_length: truncates tokens after sequence_length. None for unlimited.
659 :param minimum_occurrences: ignore tokens with less than this many occurrences
Dangerous default value [] as argument
782
783 """
784
785 def __init__(self, column, name=None, depth=None, tags=[]):786 super(MiddleOut, self).__init__(column, name, tags=tags)
787 self.depth = depth
788 self.dtype = self._type_from_cardinality()
Dangerous default value [] as argument
813 Unique encoder.
814 """
815
816 def __init__(self, column, name=None, sequence_length=None, minimum_occurrences=1, embed_scale=1, tags=[], twin=False):817 """
818 :param sequence_length: truncates tokens after sequence_length. None for unlimited.
819 :param minimum_occurrences: ignore tokens with less than this many occurrences
Dangerous default value [] as argument
888 Norm encoder.
889 """
890
891 def __init__(self, column, name=None, sequence_length=None, dtype=numpy.float32, embed_scale=1, tags=[], twin=False):892 """
893 :param sequence_length: truncates tokens after sequence_length. None for unlimited.
894 :param minimum_occurrences: ignore tokens with less than this many occurrences
Description
Do not use a mutable like list
or dictionary
as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.
Bad practice
def my_function(elem, l=[]):
l.append(elem)
return l
print(my_function(2)) # [2]
print(my_function(5)) # [2, 5]
Recommended:
def my_function(elem, l=None):
if l is None:
l = []
l.append(elem)
return l
print(my_function(2)) # [2]
print(my_function(5)) # [5]