Skip to content

Commit 070e877

Browse files
eddiejessupjreback
authored andcommitted
BUG: Fix argument order in call to super
Author: Elliot Marsden <[email protected]> Closes #12924 from eddiejessup/master and squashes the following commits: b495e32 [Elliot Marsden] BUG: Fix argument order in call to super
1 parent eeccd05 commit 070e877

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

doc/source/whatsnew/v0.18.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Bug Fixes
124124
- Bug in ``.groupby(..).resample(..)`` when the same object is called multiple times (:issue:`13174`)
125125
- Bug in ``.to_records()`` when index name is a unicode string (:issue: `13172`)
126126

127+
- Bug in calling ``.memory_usage()`` on object which doesn't implement (:issue:`12924`)
127128

128129
- Regression in ``Series.quantile`` with nans (also shows up in ``.median()`` and ``.describe()``); furthermore now names the ``Series`` with the quantile (:issue:`13098`, :issue:`13146`)
129130

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __sizeof__(self):
127127

128128
# no memory_usage attribute, so fall back to
129129
# object's 'sizeof'
130-
return super(self, PandasObject).__sizeof__()
130+
return super(PandasObject, self).__sizeof__()
131131

132132

133133
class NoNewAttributesMixin(object):

pandas/tests/test_base.py

+37-26
Original file line numberDiff line numberDiff line change
@@ -147,42 +147,46 @@ def test_values(self):
147147

148148
class TestPandasDelegate(tm.TestCase):
149149

150-
def setUp(self):
151-
pass
150+
class Delegator(object):
151+
_properties = ['foo']
152+
_methods = ['bar']
152153

153-
def test_invalida_delgation(self):
154-
# these show that in order for the delegation to work
155-
# the _delegate_* methods need to be overriden to not raise a TypeError
154+
def _set_foo(self, value):
155+
self.foo = value
156156

157-
class Delegator(object):
158-
_properties = ['foo']
159-
_methods = ['bar']
157+
def _get_foo(self):
158+
return self.foo
160159

161-
def _set_foo(self, value):
162-
self.foo = value
160+
foo = property(_get_foo, _set_foo, doc="foo property")
163161

164-
def _get_foo(self):
165-
return self.foo
162+
def bar(self, *args, **kwargs):
163+
""" a test bar method """
164+
pass
166165

167-
foo = property(_get_foo, _set_foo, doc="foo property")
166+
class Delegate(PandasDelegate):
168167

169-
def bar(self, *args, **kwargs):
170-
""" a test bar method """
171-
pass
168+
def __init__(self, obj):
169+
self.obj = obj
172170

173-
class Delegate(PandasDelegate):
171+
def setUp(self):
172+
pass
174173

175-
def __init__(self, obj):
176-
self.obj = obj
174+
def test_invalida_delgation(self):
175+
# these show that in order for the delegation to work
176+
# the _delegate_* methods need to be overriden to not raise a TypeError
177177

178-
Delegate._add_delegate_accessors(delegate=Delegator,
179-
accessors=Delegator._properties,
180-
typ='property')
181-
Delegate._add_delegate_accessors(delegate=Delegator,
182-
accessors=Delegator._methods,
183-
typ='method')
178+
self.Delegate._add_delegate_accessors(
179+
delegate=self.Delegator,
180+
accessors=self.Delegator._properties,
181+
typ='property'
182+
)
183+
self.Delegate._add_delegate_accessors(
184+
delegate=self.Delegator,
185+
accessors=self.Delegator._methods,
186+
typ='method'
187+
)
184188

185-
delegate = Delegate(Delegator())
189+
delegate = self.Delegate(self.Delegator())
186190

187191
def f():
188192
delegate.foo
@@ -199,6 +203,13 @@ def f():
199203

200204
self.assertRaises(TypeError, f)
201205

206+
def test_memory_usage(self):
207+
# Delegate does not implement memory_usage.
208+
# Check that we fall back to in-built `__sizeof__`
209+
# GH 12924
210+
delegate = self.Delegate(self.Delegator())
211+
sys.getsizeof(delegate)
212+
202213

203214
class Ops(tm.TestCase):
204215

0 commit comments

Comments
 (0)