Skip to content

Commit

Permalink
TST: clean warnings (pandas-dev#18012)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback authored Oct 28, 2017
1 parent 1977362 commit 39a6b8f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ clean_pyc:
build: clean_pyc
python setup.py build_ext --inplace

lint-diff:
git diff master --name-only -- "*.py" | grep "pandas" | xargs flake8

develop: build
-python setup.py develop

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ def _values_for_rank(self):
# reorder the categories (so rank can use the float codes)
# instead of passing an object array to rank
values = np.array(
self.rename_categories(Series(self.categories).rank())
self.rename_categories(Series(self.categories).rank().values)
)
return values

Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/indexing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def get_result(self, obj, method, key, axis):
key = obj._get_axis(axis)[key]

# in case we actually want 0 index slicing
try:
with catch_warnings(record=True):
with catch_warnings(record=True):
try:
xp = getattr(obj, method).__getitem__(_axify(obj, key, axis))
except:
xp = getattr(obj, method).__getitem__(key)
except:
xp = getattr(obj, method).__getitem__(key)

return xp

Expand Down
38 changes: 25 additions & 13 deletions pandas/tests/indexing/test_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,31 @@ def f():

# mixed index so we have label
# indexing
for idxr in [lambda x: x.ix,
lambda x: x]:
for idxr in [lambda x: x]:

def f():
with catch_warnings(record=True):
idxr(s3)[1.0]
idxr(s3)[1.0]

pytest.raises(TypeError, f)

result = idxr(s3)[1]
expected = 2
assert result == expected

# mixed index so we have label
# indexing
for idxr in [lambda x: x.ix]:
with catch_warnings(record=True):

def f():
idxr(s3)[1.0]

pytest.raises(TypeError, f)

result = idxr(s3)[1]
expected = 2
assert result == expected

pytest.raises(TypeError, lambda: s3.iloc[1.0])
pytest.raises(KeyError, lambda: s3.loc[1.0])

Expand Down Expand Up @@ -479,16 +491,14 @@ def test_slice_integer_frame_getitem(self):
index = index(5)
s = DataFrame(np.random.randn(5, 2), index=index)

for idxr in [lambda x: x.loc,
lambda x: x.ix]:
def f(idxr):

# getitem
for l in [slice(0.0, 1),
slice(0, 1.0),
slice(0.0, 1.0)]:

with catch_warnings(record=True):
result = idxr(s)[l]
result = idxr(s)[l]
indexer = slice(0, 2)
self.check(result, s, indexer, False)

Expand Down Expand Up @@ -516,8 +526,7 @@ def f():
(slice(0, 0.5), slice(0, 1)),
(slice(0.5, 1.5), slice(1, 2))]:

with catch_warnings(record=True):
result = idxr(s)[l]
result = idxr(s)[l]
self.check(result, s, res, False)

# positional indexing
Expand All @@ -532,9 +541,8 @@ def f():
slice(3.0, 4.0)]:

sc = s.copy()
with catch_warnings(record=True):
idxr(sc)[l] = 0
result = idxr(sc)[l].values.ravel()
idxr(sc)[l] = 0
result = idxr(sc)[l].values.ravel()
assert (result == 0).all()

# positional indexing
Expand All @@ -543,6 +551,10 @@ def f():

pytest.raises(TypeError, f)

f(lambda x: x.loc)
with catch_warnings(record=True):
f(lambda x: x.ix)

def test_slice_float(self):

# same as above, but for floats
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,10 @@ def test_partial_boolean_frame_indexing(self):

def test_no_reference_cycle(self):
df = pd.DataFrame({'a': [0, 1], 'b': [2, 3]})
for name in ('loc', 'iloc', 'ix', 'at', 'iat'):
for name in ('loc', 'iloc', 'at', 'iat'):
getattr(df, name)
with catch_warnings(record=True):
getattr(df, 'ix')
wr = weakref.ref(df)
del df
assert wr() is None
Expand Down

0 comments on commit 39a6b8f

Please sign in to comment.