Skip to content

Commit 92cf968

Browse files
committed
Merge pull request pandas-dev#11827 from proinsias/mutable_default_args
CLN: Use sentinel values instead of mutable default arguments
2 parents 471b7c7 + 4d47189 commit 92cf968

File tree

8 files changed

+29
-9
lines changed

8 files changed

+29
-9
lines changed

pandas/compat/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,10 @@ def setdefault(self, key, default=None):
475475
self[key] = default
476476
return default
477477

478-
def __repr__(self, _repr_running={}):
478+
def __repr__(self, _repr_running=None):
479479
"""od.__repr__() <==> repr(od)"""
480+
if _repr_running is None:
481+
_repr_running = {}
480482
call_key = id(self), _get_ident()
481483
if call_key in _repr_running:
482484
return '...'

pandas/core/index.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,9 @@ def __setstate__(self, state):
11491149
raise Exception("invalid pickle state")
11501150
_unpickle_compat = __setstate__
11511151

1152-
def __deepcopy__(self, memo={}):
1152+
def __deepcopy__(self, memo=None):
1153+
if memo is None:
1154+
memo = {}
11531155
return self.copy(deep=True)
11541156

11551157
def __nonzero__(self):

pandas/core/internals.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4740,8 +4740,10 @@ def trim_join_unit(join_unit, length):
47404740

47414741

47424742
class JoinUnit(object):
4743-
def __init__(self, block, shape, indexers={}):
4743+
def __init__(self, block, shape, indexers=None):
47444744
# Passing shape explicitly is required for cases when block is None.
4745+
if indexers is None:
4746+
indexers = {}
47454747
self.block = block
47464748
self.indexers = indexers
47474749
self.shape = shape

pandas/core/panel.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _ensure_like_indices(time, panels):
5555
return time, panels
5656

5757

58-
def panel_index(time, panels, names=['time', 'panel']):
58+
def panel_index(time, panels, names=None):
5959
"""
6060
Returns a multi-index suitable for a panel-like DataFrame
6161
@@ -94,6 +94,8 @@ def panel_index(time, panels, names=['time', 'panel']):
9494
(1961, 'B'), (1961, 'C'), (1962, 'A'), (1962, 'B'),
9595
(1962, 'C')], dtype=object)
9696
"""
97+
if names is None:
98+
names = ['time', 'panel']
9799
time, panels = _ensure_like_indices(time, panels)
98100
time_factor = Categorical.from_array(time, ordered=True)
99101
panel_factor = Categorical.from_array(panels, ordered=True)

pandas/io/auth.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ class AuthenticationConfigError(ValueError):
4545
# a secure place.
4646

4747

48-
def process_flags(flags=[]):
48+
def process_flags(flags=None):
4949
"""Uses the command-line flags to set the logging level.
5050
5151
Args:
5252
argv: List of command line arguments passed to the python script.
5353
"""
54+
if flags is None:
55+
flags = []
5456

5557
# Let the gflags module process the command-line arguments.
5658
try:

pandas/io/wb.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
'VIR', 'VNM', 'VUT', 'WLF', 'WSM', 'YEM', 'ZAF', 'ZMB', \
8484
'ZWE', 'all', 'ALL', 'All']
8585

86-
def download(country=['MX', 'CA', 'US'], indicator=['NY.GDP.MKTP.CD', 'NY.GNS.ICTR.ZS'],
86+
def download(country=None, indicator=None,
8787
start=2003, end=2005,errors='warn'):
8888
"""
8989
Download data series from the World Bank's World Development Indicators
@@ -123,6 +123,10 @@ def download(country=['MX', 'CA', 'US'], indicator=['NY.GDP.MKTP.CD', 'NY.GNS.IC
123123
indicator value.
124124
125125
"""
126+
if country is None:
127+
country = ['MX', 'CA', 'US']
128+
if indicator is None:
129+
indicator = ['NY.GDP.MKTP.CD', 'NY.GNS.ICTR.ZS']
126130

127131
if type(country) == str:
128132
country = [country]

pandas/stats/fama_macbeth.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class FamaMacBeth(StringMixin):
3131
def __init__(self, y, x, intercept=True, nw_lags=None,
3232
nw_lags_beta=None,
3333
entity_effects=False, time_effects=False, x_effects=None,
34-
cluster=None, dropped_dummies={}, verbose=False):
34+
cluster=None, dropped_dummies=None, verbose=False):
35+
if dropped_dummies is None:
36+
dropped_dummies = {}
3537
self._nw_lags_beta = nw_lags_beta
3638

3739
from pandas.stats.plm import MovingPanelOLS
@@ -143,7 +145,9 @@ class MovingFamaMacBeth(FamaMacBeth):
143145
def __init__(self, y, x, window_type='rolling', window=10,
144146
intercept=True, nw_lags=None, nw_lags_beta=None,
145147
entity_effects=False, time_effects=False, x_effects=None,
146-
cluster=None, dropped_dummies={}, verbose=False):
148+
cluster=None, dropped_dummies=None, verbose=False):
149+
if dropped_dummies is None:
150+
dropped_dummies = {}
147151
self._window_type = common._get_window_type(window_type)
148152
self._window = window
149153

pandas/tools/plotting.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
653653
@deprecate_kwarg(old_arg_name='data', new_arg_name='frame', stacklevel=3)
654654
def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
655655
use_columns=False, xticks=None, colormap=None,
656-
axvlines=True, axvlines_kwds={'linewidth':1,'color':'black'}, **kwds):
656+
axvlines=True, axvlines_kwds=None, **kwds):
657657
"""Parallel coordinates plotting.
658658
659659
Parameters
@@ -693,6 +693,8 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
693693
>>> parallel_coordinates(df, 'Name', color=('#556270', '#4ECDC4', '#C7F464'))
694694
>>> plt.show()
695695
"""
696+
if axvlines_kwds is None:
697+
axvlines_kwds = {'linewidth':1,'color':'black'}
696698
import matplotlib.pyplot as plt
697699

698700
n = len(frame)

0 commit comments

Comments
 (0)