From 19dbef20bbcf7220e94fffcff2561aee08ef5c66 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 23 Dec 2019 01:56:12 +0200 Subject: [PATCH] Replaced xrange with range --- ci/code_checks.sh | 8 ++++++-- pandas/_libs/testing.pyx | 2 +- pandas/tests/arrays/categorical/test_constructors.py | 6 ++---- pandas/tests/frame/test_block_internals.py | 4 ---- pandas/tests/io/test_html.py | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 559cedd62e7ce..94eaab0a5b4da 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -52,7 +52,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then black --version MSG='Checking black formatting' ; echo $MSG - black . --check + black . --check RET=$(($RET + $?)) ; echo $MSG "DONE" # `setup.cfg` contains the list of error codes that are being ignored in flake8 @@ -104,7 +104,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then isort --version-number # Imports - Check formatting using isort see setup.cfg for settings - MSG='Check import format using isort ' ; echo $MSG + MSG='Check import format using isort' ; echo $MSG ISORT_CMD="isort --recursive --check-only pandas asv_bench" if [[ "$GITHUB_ACTIONS" == "true" ]]; then eval $ISORT_CMD | awk '{print "##[error]" $0}'; RET=$(($RET + ${PIPESTATUS[0]})) @@ -203,6 +203,10 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then invgrep -R --include=*.{py,pyx} '\.__class__' pandas RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Check for use of xrange instead of range' ; echo $MSG + invgrep -R --include=*.{py,pyx} 'xrange' pandas + RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Check that no file in the repo contains trailing whitespaces' ; echo $MSG INVGREP_APPEND=" <- trailing whitespaces found" invgrep -RI --exclude=\*.{svg,c,cpp,html,js} --exclude-dir=env "\s$" * diff --git a/pandas/_libs/testing.pyx b/pandas/_libs/testing.pyx index e41914f3aa9ad..026bd7a44a509 100644 --- a/pandas/_libs/testing.pyx +++ b/pandas/_libs/testing.pyx @@ -159,7 +159,7 @@ cpdef assert_almost_equal(a, b, raise_assert_detail(obj, f"{obj} length are different", na, nb, r) - for i in xrange(len(a)): + for i in range(len(a)): try: assert_almost_equal(a[i], b[i], check_less_precise=check_less_precise) diff --git a/pandas/tests/arrays/categorical/test_constructors.py b/pandas/tests/arrays/categorical/test_constructors.py index 0762523d53428..6c8b654c1955c 100644 --- a/pandas/tests/arrays/categorical/test_constructors.py +++ b/pandas/tests/arrays/categorical/test_constructors.py @@ -277,21 +277,19 @@ def test_constructor_with_index(self): def test_constructor_with_generator(self): # This was raising an Error in isna(single_val).any() because isna # returned a scalar for a generator - xrange = range exp = Categorical([0, 1, 2]) cat = Categorical((x for x in [0, 1, 2])) tm.assert_categorical_equal(cat, exp) - cat = Categorical(xrange(3)) + cat = Categorical(range(3)) tm.assert_categorical_equal(cat, exp) - # This uses xrange internally MultiIndex.from_product([range(5), ["a", "b", "c"]]) # check that categories accept generators and sequences cat = Categorical([0, 1, 2], categories=(x for x in [0, 1, 2])) tm.assert_categorical_equal(cat, exp) - cat = Categorical([0, 1, 2], categories=xrange(3)) + cat = Categorical([0, 1, 2], categories=range(3)) tm.assert_categorical_equal(cat, exp) @pytest.mark.parametrize( diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index b27e7c217c4c2..eb8febb10a646 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -585,10 +585,6 @@ def test_strange_column_corruption_issue(self): df = DataFrame(index=[0, 1]) df[0] = np.nan wasCol = {} - # uncommenting these makes the results match - # for col in xrange(100, 200): - # wasCol[col] = 1 - # df[col] = np.nan for i, dt in enumerate(df.index): for col in range(100, 200): diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 39cbe843d1f2b..bc26615d1aad5 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -178,7 +178,7 @@ def test_skiprows_int(self): assert_framelist_equal(df1, df2) - def test_skiprows_xrange(self): + def test_skiprows_range(self): df1 = self.read_html(self.spam_data, ".*Water.*", skiprows=range(2))[0] df2 = self.read_html(self.spam_data, "Unit", skiprows=range(2))[0] tm.assert_frame_equal(df1, df2)