Skip to content

Commit fe971f6

Browse files
ShaharNavehWillAyd
authored andcommitted
Replaced xrange with range (#30417)
1 parent c0cf2c2 commit fe971f6

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

ci/code_checks.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
5252
black --version
5353

5454
MSG='Checking black formatting' ; echo $MSG
55-
black . --check
55+
black . --check
5656
RET=$(($RET + $?)) ; echo $MSG "DONE"
5757

5858
# `setup.cfg` contains the list of error codes that are being ignored in flake8
@@ -104,7 +104,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
104104
isort --version-number
105105

106106
# Imports - Check formatting using isort see setup.cfg for settings
107-
MSG='Check import format using isort ' ; echo $MSG
107+
MSG='Check import format using isort' ; echo $MSG
108108
ISORT_CMD="isort --recursive --check-only pandas asv_bench"
109109
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
110110
eval $ISORT_CMD | awk '{print "##[error]" $0}'; RET=$(($RET + ${PIPESTATUS[0]}))
@@ -203,6 +203,10 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
203203
invgrep -R --include=*.{py,pyx} '\.__class__' pandas
204204
RET=$(($RET + $?)) ; echo $MSG "DONE"
205205

206+
MSG='Check for use of xrange instead of range' ; echo $MSG
207+
invgrep -R --include=*.{py,pyx} 'xrange' pandas
208+
RET=$(($RET + $?)) ; echo $MSG "DONE"
209+
206210
MSG='Check that no file in the repo contains trailing whitespaces' ; echo $MSG
207211
INVGREP_APPEND=" <- trailing whitespaces found"
208212
invgrep -RI --exclude=\*.{svg,c,cpp,html,js} --exclude-dir=env "\s$" *

pandas/_libs/testing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ cpdef assert_almost_equal(a, b,
159159

160160
raise_assert_detail(obj, f"{obj} length are different", na, nb, r)
161161

162-
for i in xrange(len(a)):
162+
for i in range(len(a)):
163163
try:
164164
assert_almost_equal(a[i], b[i],
165165
check_less_precise=check_less_precise)

pandas/tests/arrays/categorical/test_constructors.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,19 @@ def test_constructor_with_index(self):
277277
def test_constructor_with_generator(self):
278278
# This was raising an Error in isna(single_val).any() because isna
279279
# returned a scalar for a generator
280-
xrange = range
281280

282281
exp = Categorical([0, 1, 2])
283282
cat = Categorical((x for x in [0, 1, 2]))
284283
tm.assert_categorical_equal(cat, exp)
285-
cat = Categorical(xrange(3))
284+
cat = Categorical(range(3))
286285
tm.assert_categorical_equal(cat, exp)
287286

288-
# This uses xrange internally
289287
MultiIndex.from_product([range(5), ["a", "b", "c"]])
290288

291289
# check that categories accept generators and sequences
292290
cat = Categorical([0, 1, 2], categories=(x for x in [0, 1, 2]))
293291
tm.assert_categorical_equal(cat, exp)
294-
cat = Categorical([0, 1, 2], categories=xrange(3))
292+
cat = Categorical([0, 1, 2], categories=range(3))
295293
tm.assert_categorical_equal(cat, exp)
296294

297295
@pytest.mark.parametrize(

pandas/tests/frame/test_block_internals.py

-4
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,6 @@ def test_strange_column_corruption_issue(self):
585585
df = DataFrame(index=[0, 1])
586586
df[0] = np.nan
587587
wasCol = {}
588-
# uncommenting these makes the results match
589-
# for col in xrange(100, 200):
590-
# wasCol[col] = 1
591-
# df[col] = np.nan
592588

593589
for i, dt in enumerate(df.index):
594590
for col in range(100, 200):

pandas/tests/io/test_html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_skiprows_int(self):
178178

179179
assert_framelist_equal(df1, df2)
180180

181-
def test_skiprows_xrange(self):
181+
def test_skiprows_range(self):
182182
df1 = self.read_html(self.spam_data, ".*Water.*", skiprows=range(2))[0]
183183
df2 = self.read_html(self.spam_data, "Unit", skiprows=range(2))[0]
184184
tm.assert_frame_equal(df1, df2)

0 commit comments

Comments
 (0)