Skip to content

Commit

Permalink
MAINT: Python2 Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
sethtroisi committed Jan 21, 2020
1 parent 19b96a1 commit 6737f24
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 189 deletions.
1 change: 1 addition & 0 deletions numpy/core/code_generators/generate_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def english_upper(s):
],
TD(O, f='PyNumber_Multiply'),
),
#'divide' : aliased to true_divide in umathmodule.c:initumath
'floor_divide':
Ufunc(2, 1, None, # One is only a unit to the right, not the left
docstrings.get('numpy.core.umath.floor_divide'),
Expand Down
3 changes: 1 addition & 2 deletions numpy/core/tests/test_memmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import shutil
import mmap
import pytest
from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryFile, mktemp, mkdtemp

from numpy import (
memmap, sum, average, product, ndarray, isscalar, add, subtract, multiply)
from numpy.compat import Path

from numpy import arange, allclose, asarray
from numpy.testing import (
Expand Down Expand Up @@ -74,7 +74,6 @@ def test_filename(self):
del b
del fp

@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
def test_path(self):
tmpname = mktemp('', 'mmap', dir=self.tempdir)
fp = memmap(Path(tmpname), dtype=self.dtype, mode='w+',
Expand Down
3 changes: 1 addition & 2 deletions numpy/core/tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import collections as collections_abc
import textwrap
from os import path
from pathlib import Path
import pytest

import numpy as np
from numpy.compat import Path
from numpy.testing import (
assert_, assert_equal, assert_array_equal, assert_array_almost_equal,
assert_raises, temppath,
Expand Down Expand Up @@ -319,7 +319,6 @@ def test_zero_width_strings(self):
assert_equal(rec['f1'], [b'', b'', b''])


@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
class TestPathUsage:
# Test that pathlib.Path can be used
def test_tofile_fromfile(self):
Expand Down
2 changes: 1 addition & 1 deletion numpy/distutils/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Colored log, requires Python 2.3 or up.
# Colored log
import sys
from distutils.log import *
from distutils.log import Log as old_Log
Expand Down
5 changes: 2 additions & 3 deletions numpy/lib/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io
import re
import pytest
from pathlib import Path
from tempfile import NamedTemporaryFile
from io import BytesIO, StringIO
from datetime import datetime
Expand All @@ -15,7 +16,7 @@
import numpy as np
import numpy.ma as ma
from numpy.lib._iotools import ConverterError, ConversionWarning
from numpy.compat import asbytes, bytes, Path
from numpy.compat import asbytes, bytes
from numpy.ma.testutils import assert_equal
from numpy.testing import (
assert_warns, assert_, assert_raises_regex, assert_raises,
Expand Down Expand Up @@ -362,7 +363,6 @@ def test_structured_padded(self):
c.seek(0)
assert_equal(c.readlines(), [b'1 3\n', b'4 6\n'])

@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
def test_multifield_view(self):
a = np.ones(1, dtype=[('x', 'i4'), ('y', 'i4'), ('z', 'f4')])
v = a[['x', 'z']]
Expand Down Expand Up @@ -2339,7 +2339,6 @@ def test_auto_dtype_largeint(self):
assert_equal(test['f2'], 1024)


@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
class TestPathUsage:
# Test that pathlib.Path can be used
def test_loadtxt(self):
Expand Down
2 changes: 1 addition & 1 deletion numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4744,7 +4744,7 @@ def ids(self):
>>> x = np.ma.array([1, 2, 3])
>>> x.ids()
(166691080, 3083169284L) # may vary
(166691080, 3083169284) # may vary
"""
if self._mask is nomask:
Expand Down
27 changes: 10 additions & 17 deletions numpy/matrixlib/tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,17 @@ def test_matrix_builder(self):

def test_array_equal_error_message_matrix():
# 2018-04-29: moved here from testing.tests.test_utils.
try:
with pytest.raises(AssertionError) as exc_info:
assert_equal(np.array([1, 2]), np.matrix([1, 2]))
except AssertionError as e:
msg = str(e)
msg2 = msg.replace("shapes (2L,), (1L, 2L)", "shapes (2,), (1, 2)")
msg_reference = textwrap.dedent("""\
Arrays are not equal
(shapes (2,), (1, 2) mismatch)
x: array([1, 2])
y: matrix([[1, 2]])""")
try:
assert_equal(msg, msg_reference)
except AssertionError:
assert_equal(msg2, msg_reference)
else:
raise AssertionError("Did not raise")
msg = str(exc_info.value)
msg_reference = textwrap.dedent("""\
Arrays are not equal
(shapes (2,), (1, 2) mismatch)
x: array([1, 2])
y: matrix([[1, 2]])""")
assert_equal(msg, msg_reference)


def test_array_almost_equal_matrix():
Expand Down
18 changes: 0 additions & 18 deletions numpy/testing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,6 @@ def test_complex(self):
self._assert_func(x, x)
self._test_not_equal(x, y)

def test_error_message(self):
with pytest.raises(AssertionError) as exc_info:
self._assert_func(np.array([1, 2]), np.array([[1, 2]]))
msg = str(exc_info.value)
msg2 = msg.replace("shapes (2L,), (1L, 2L)", "shapes (2,), (1, 2)")
msg_reference = textwrap.dedent("""\
Arrays are not equal
(shapes (2,), (1, 2) mismatch)
x: array([1, 2])
y: array([[1, 2]])""")

try:
assert_equal(msg, msg_reference)
except AssertionError:
assert_equal(msg2, msg_reference)

def test_object(self):
#gh-12942
import datetime
Expand Down
2 changes: 1 addition & 1 deletion numpy/tests/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def visit_Call(self, node):
if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings':
if node.args[0].s == "ignore":
raise AssertionError(
"ignore filter should not be used; found in "
"warnings should have an appropriate stacklevel; found in "
"{} on line {}".format(self.__filename, node.lineno))

if p.ls[-1] == 'warn' and (
Expand Down
Loading

0 comments on commit 6737f24

Please sign in to comment.