Skip to content

Commit 1cd9eb5

Browse files
committed
TST: NumPy 1.5.1 workaround, GH #353
1 parent 8a9bc9e commit 1cd9eb5

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

pandas/core/series.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
__all__ = ['Series', 'TimeSeries']
3535

36+
_np_version = np.version.short_version
37+
3638
#-------------------------------------------------------------------------------
3739
# Wrapper function for Series arithmetic methods
3840

@@ -59,8 +61,17 @@ def wrapper(self, other):
5961
elif isinstance(other, DataFrame):
6062
return NotImplemented
6163
else:
64+
# GH #353, NumPy 1.5.1 workaround
65+
try:
66+
result_values = op(self.values, other)
67+
except TypeError:
68+
if _np_version.startswith('1.5'): # pragma: no cover
69+
result_values = [op(x, other) for x in self.values]
70+
else:
71+
raise
72+
6273
# scalars
63-
return Series(op(self.values, other), index=self.index,
74+
return Series(result_values, index=self.index,
6475
name=self.name)
6576
return wrapper
6677

pandas/util/decorators.py

+57
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,60 @@ def wrapped(*args, **kwargs):
113113
sys.stdout = sys.__stdout__
114114

115115
return wrapped
116+
117+
118+
class KnownFailureTest(Exception):
119+
'''Raise this exception to mark a test as a known failing test.'''
120+
pass
121+
122+
def knownfailureif(fail_condition, msg=None):
123+
"""
124+
Make function raise KnownFailureTest exception if given condition is true.
125+
126+
If the condition is a callable, it is used at runtime to dynamically
127+
make the decision. This is useful for tests that may require costly
128+
imports, to delay the cost until the test suite is actually executed.
129+
130+
Parameters
131+
----------
132+
fail_condition : bool or callable
133+
Flag to determine whether to mark the decorated test as a known
134+
failure (if True) or not (if False).
135+
msg : str, optional
136+
Message to give on raising a KnownFailureTest exception.
137+
Default is None.
138+
139+
Returns
140+
-------
141+
decorator : function
142+
Decorator, which, when applied to a function, causes SkipTest
143+
to be raised when `skip_condition` is True, and the function
144+
to be called normally otherwise.
145+
146+
Notes
147+
-----
148+
The decorator itself is decorated with the ``nose.tools.make_decorator``
149+
function in order to transmit function name, and various other metadata.
150+
151+
"""
152+
if msg is None:
153+
msg = 'Test skipped due to known failure'
154+
155+
# Allow for both boolean or callable known failure conditions.
156+
if callable(fail_condition):
157+
fail_val = fail_condition
158+
else:
159+
fail_val = lambda: fail_condition
160+
161+
def knownfail_decorator(f):
162+
# Local import to avoid a hard nose dependency and only incur the
163+
# import time overhead at actual test-time.
164+
import nose
165+
def knownfailer(*args, **kwargs):
166+
if fail_val():
167+
raise KnownFailureTest, msg
168+
else:
169+
return f(*args, **kwargs)
170+
return nose.tools.make_decorator(f)(knownfailer)
171+
172+
return knownfail_decorator

0 commit comments

Comments
 (0)