Skip to content

Commit 915162e

Browse files
committed
TST: more misc test coverage
1 parent 79fc8c4 commit 915162e

File tree

3 files changed

+35
-85
lines changed

3 files changed

+35
-85
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,7 +4660,7 @@ def _get_bool_data(self):
46604660
if self._is_mixed_type:
46614661
bool_data = self._data.get_bool_data()
46624662
return DataFrame(bool_data, copy=False)
4663-
else:
4663+
else: # pragma: no cover
46644664
if self.values.dtype == np.bool_:
46654665
return self
46664666
else:
@@ -4896,7 +4896,8 @@ def where(self, cond, other):
48964896
if isinstance(cond, np.ndarray):
48974897
if cond.shape != self.shape:
48984898
raise ValueError('Array onditional must be same shape as self')
4899-
cond = self._constructor(cond, index=self.index, columns=self.columns)
4899+
cond = self._constructor(cond, index=self.index,
4900+
columns=self.columns)
49004901
if cond.shape != self.shape:
49014902
cond = cond.reindex(self.index, columns=self.columns)
49024903
cond = cond.fillna(False)

pandas/core/strings.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,6 @@
66
from pandas.core.series import Series
77
import re
88
import pandas.lib as lib
9-
import pandas.core.common as com
10-
import operator
11-
12-
13-
class repeat(object):
14-
def __init__(self, obj):
15-
self.obj = obj
16-
17-
def __getitem__(self, i):
18-
return self.obj
19-
20-
21-
class azip(object):
22-
def __init__(self, *args):
23-
self.cols = []
24-
for a in args:
25-
if np.isscalar(a):
26-
self.cols.append(repeat(a))
27-
else:
28-
self.cols.append(a)
29-
30-
def __getitem__(self, i):
31-
return [col[i] for col in self.cols]
32-
33-
34-
def map_iter_args(arr, f, otherargs, n_otherargs, required, n_results):
35-
'''
36-
Substitute for np.vectorize with pandas-friendly dtype inference
37-
38-
Parameters
39-
----------
40-
arr : ndarray
41-
f : function
42-
43-
Returns
44-
-------
45-
mapped : ndarray
46-
'''
47-
notnull = com.notnull
48-
49-
n = len(arr)
50-
result = np.empty((n, n_results), dtype=object)
51-
for i, val in enumerate(arr):
52-
args = otherargs[i]
53-
if notnull(val) and all(notnull(args[r]) for r in required):
54-
result[i] = f(val, *args)
55-
else:
56-
result[i] = [np.nan] * n_results
57-
58-
return [lib.maybe_convert_objects(col, try_float=0) for col in result.T]
59-
60-
61-
def auto_map(arr, f, otherargs, n_results=1, required='all'):
62-
from pandas.core.series import Series
63-
64-
if all(np.isscalar(a) for a in otherargs):
65-
res = lib.map_infer(arr, lambda v: f(v, *otherargs))
66-
return Series(res, index=arr.index, copy=False)
67-
68-
n_otherargs = len(otherargs)
69-
if required == 'all':
70-
required = list(range(n_otherargs))
71-
res = map_iter_args(arr, f, azip(*otherargs), n_otherargs,
72-
required, n_results)
73-
res = [Series(col, index=arr.index, copy=False) for col in res]
74-
if n_results == 1:
75-
return res[0]
76-
return res
77-
78-
79-
def mapwrap(f, n_results_default=1, required='all'):
80-
# @wraps(f)
81-
82-
def wrapped(arr, n_results=None, *otherargs):
83-
n_results = n_results or n_results_default
84-
return auto_map(arr, f, otherargs, n_results, required)
85-
86-
return wrapped
87-
88-
startswith = mapwrap(lambda x, p: x.startswith(p))
89-
contains = mapwrap(lambda x, p: x.__contains__(p))
90-
upper = mapwrap(lambda x: x.upper())
91-
lower = mapwrap(lambda x: x.lower())
929

9310

9411
def _get_array_list(arr, others):

pandas/tests/test_frame.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5151,8 +5151,13 @@ def test_where(self):
51515151

51525152
other1 = df + 1
51535153
rs = df.where(cond, other1)
5154+
rs2 = df.where(cond.values, other1)
51545155
for k, v in rs.iteritems():
51555156
assert_series_equal(v, np.where(cond[k], df[k], other1[k]))
5157+
assert_frame_equal(rs, rs2)
5158+
5159+
# it works!
5160+
rs = df.where(cond[1:], other1)
51565161

51575162
other2 = (df + 1).values
51585163
rs = df.where(cond, other2)
@@ -7274,6 +7279,33 @@ def test_any_all(self):
72747279
self._check_bool_op('any', np.any, has_skipna=True, has_bool_only=True)
72757280
self._check_bool_op('all', np.all, has_skipna=True, has_bool_only=True)
72767281

7282+
7283+
df = DataFrame(randn(10, 4)) > 0
7284+
df.any(1)
7285+
df.all(1)
7286+
df.any(1, bool_only=True)
7287+
df.all(1, bool_only=True)
7288+
7289+
# skip pathological failure cases
7290+
# class CantNonzero(object):
7291+
7292+
# def __nonzero__(self):
7293+
# raise ValueError
7294+
7295+
# df[4] = CantNonzero()
7296+
7297+
# it works!
7298+
# df.any(1)
7299+
# df.all(1)
7300+
# df.any(1, bool_only=True)
7301+
# df.all(1, bool_only=True)
7302+
7303+
# df[4][4] = np.nan
7304+
# df.any(1)
7305+
# df.all(1)
7306+
# df.any(1, bool_only=True)
7307+
# df.all(1, bool_only=True)
7308+
72777309
def test_consolidate_datetime64(self):
72787310
# numpy vstack bug
72797311

0 commit comments

Comments
 (0)