Skip to content

Commit e71c02a

Browse files
jschendeljorisvandenbossche
authored andcommitted
CLN: Use new-style classes instead of old-style classes (#20563)
1 parent d305d6a commit e71c02a

15 files changed

+79
-71
lines changed

ci/lint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ if [ "$LINT" ]; then
165165
RET=1
166166
fi
167167
echo "Check for deprecated messages without sphinx directive DONE"
168+
169+
echo "Check for old-style classes"
170+
grep -R --include="*.py" -E "class\s\S*[^)]:" pandas scripts
171+
172+
if [ $? = "0" ]; then
173+
RET=1
174+
fi
175+
echo "Check for old-style classes DONE"
168176

169177
else
170178
echo "NOT Linting"

pandas/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_keywords():
2626
return keywords
2727

2828

29-
class VersioneerConfig:
29+
class VersioneerConfig(object):
3030
pass
3131

3232

pandas/io/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def __next__(self):
534534
row = next(self.reader)
535535
return [compat.text_type(s, "utf-8") for s in row]
536536

537-
class UnicodeWriter:
537+
class UnicodeWriter(object):
538538

539539
"""
540540
A CSV writer which will write rows to CSV file "f",

pandas/io/sas/sas7bdat.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def _get_subheader_index(self, signature, compression, ptype):
321321
(compression == 0))
322322
f2 = (ptype == const.compressed_subheader_type)
323323
if (self.compression != "") and f1 and f2:
324-
index = const.index.dataSubheaderIndex
324+
index = const.SASIndex.data_subheader_index
325325
else:
326326
self.close()
327327
raise ValueError("Unknown subheader signature")
@@ -360,23 +360,23 @@ def _process_subheader(self, subheader_index, pointer):
360360
offset = pointer.offset
361361
length = pointer.length
362362

363-
if subheader_index == const.index.rowSizeIndex:
363+
if subheader_index == const.SASIndex.row_size_index:
364364
processor = self._process_rowsize_subheader
365-
elif subheader_index == const.index.columnSizeIndex:
365+
elif subheader_index == const.SASIndex.column_size_index:
366366
processor = self._process_columnsize_subheader
367-
elif subheader_index == const.index.columnTextIndex:
367+
elif subheader_index == const.SASIndex.column_text_index:
368368
processor = self._process_columntext_subheader
369-
elif subheader_index == const.index.columnNameIndex:
369+
elif subheader_index == const.SASIndex.column_name_index:
370370
processor = self._process_columnname_subheader
371-
elif subheader_index == const.index.columnAttributesIndex:
371+
elif subheader_index == const.SASIndex.column_attributes_index:
372372
processor = self._process_columnattributes_subheader
373-
elif subheader_index == const.index.formatAndLabelIndex:
373+
elif subheader_index == const.SASIndex.format_and_label_index:
374374
processor = self._process_format_subheader
375-
elif subheader_index == const.index.columnListIndex:
375+
elif subheader_index == const.SASIndex.column_list_index:
376376
processor = self._process_columnlist_subheader
377-
elif subheader_index == const.index.subheaderCountsIndex:
377+
elif subheader_index == const.SASIndex.subheader_counts_index:
378378
processor = self._process_subheader_counts
379-
elif subheader_index == const.index.dataSubheaderIndex:
379+
elif subheader_index == const.SASIndex.data_subheader_index:
380380
self._current_page_data_subheader_pointers.append(pointer)
381381
return
382382
else:

pandas/io/sas/sas_constants.py

+40-40
Original file line numberDiff line numberDiff line change
@@ -102,49 +102,49 @@
102102
61: "wcyrillic", 62: "wlatin1", 90: "ebcdic870"}
103103

104104

105-
class index:
106-
rowSizeIndex = 0
107-
columnSizeIndex = 1
108-
subheaderCountsIndex = 2
109-
columnTextIndex = 3
110-
columnNameIndex = 4
111-
columnAttributesIndex = 5
112-
formatAndLabelIndex = 6
113-
columnListIndex = 7
114-
dataSubheaderIndex = 8
105+
class SASIndex(object):
106+
row_size_index = 0
107+
column_size_index = 1
108+
subheader_counts_index = 2
109+
column_text_index = 3
110+
column_name_index = 4
111+
column_attributes_index = 5
112+
format_and_label_index = 6
113+
column_list_index = 7
114+
data_subheader_index = 8
115115

116116

117117
subheader_signature_to_index = {
118-
b"\xF7\xF7\xF7\xF7": index.rowSizeIndex,
119-
b"\x00\x00\x00\x00\xF7\xF7\xF7\xF7": index.rowSizeIndex,
120-
b"\xF7\xF7\xF7\xF7\x00\x00\x00\x00": index.rowSizeIndex,
121-
b"\xF7\xF7\xF7\xF7\xFF\xFF\xFB\xFE": index.rowSizeIndex,
122-
b"\xF6\xF6\xF6\xF6": index.columnSizeIndex,
123-
b"\x00\x00\x00\x00\xF6\xF6\xF6\xF6": index.columnSizeIndex,
124-
b"\xF6\xF6\xF6\xF6\x00\x00\x00\x00": index.columnSizeIndex,
125-
b"\xF6\xF6\xF6\xF6\xFF\xFF\xFB\xFE": index.columnSizeIndex,
126-
b"\x00\xFC\xFF\xFF": index.subheaderCountsIndex,
127-
b"\xFF\xFF\xFC\x00": index.subheaderCountsIndex,
128-
b"\x00\xFC\xFF\xFF\xFF\xFF\xFF\xFF": index.subheaderCountsIndex,
129-
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFC\x00": index.subheaderCountsIndex,
130-
b"\xFD\xFF\xFF\xFF": index.columnTextIndex,
131-
b"\xFF\xFF\xFF\xFD": index.columnTextIndex,
132-
b"\xFD\xFF\xFF\xFF\xFF\xFF\xFF\xFF": index.columnTextIndex,
133-
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD": index.columnTextIndex,
134-
b"\xFF\xFF\xFF\xFF": index.columnNameIndex,
135-
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF": index.columnNameIndex,
136-
b"\xFC\xFF\xFF\xFF": index.columnAttributesIndex,
137-
b"\xFF\xFF\xFF\xFC": index.columnAttributesIndex,
138-
b"\xFC\xFF\xFF\xFF\xFF\xFF\xFF\xFF": index.columnAttributesIndex,
139-
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC": index.columnAttributesIndex,
140-
b"\xFE\xFB\xFF\xFF": index.formatAndLabelIndex,
141-
b"\xFF\xFF\xFB\xFE": index.formatAndLabelIndex,
142-
b"\xFE\xFB\xFF\xFF\xFF\xFF\xFF\xFF": index.formatAndLabelIndex,
143-
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFB\xFE": index.formatAndLabelIndex,
144-
b"\xFE\xFF\xFF\xFF": index.columnListIndex,
145-
b"\xFF\xFF\xFF\xFE": index.columnListIndex,
146-
b"\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF": index.columnListIndex,
147-
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE": index.columnListIndex}
118+
b"\xF7\xF7\xF7\xF7": SASIndex.row_size_index,
119+
b"\x00\x00\x00\x00\xF7\xF7\xF7\xF7": SASIndex.row_size_index,
120+
b"\xF7\xF7\xF7\xF7\x00\x00\x00\x00": SASIndex.row_size_index,
121+
b"\xF7\xF7\xF7\xF7\xFF\xFF\xFB\xFE": SASIndex.row_size_index,
122+
b"\xF6\xF6\xF6\xF6": SASIndex.column_size_index,
123+
b"\x00\x00\x00\x00\xF6\xF6\xF6\xF6": SASIndex.column_size_index,
124+
b"\xF6\xF6\xF6\xF6\x00\x00\x00\x00": SASIndex.column_size_index,
125+
b"\xF6\xF6\xF6\xF6\xFF\xFF\xFB\xFE": SASIndex.column_size_index,
126+
b"\x00\xFC\xFF\xFF": SASIndex.subheader_counts_index,
127+
b"\xFF\xFF\xFC\x00": SASIndex.subheader_counts_index,
128+
b"\x00\xFC\xFF\xFF\xFF\xFF\xFF\xFF": SASIndex.subheader_counts_index,
129+
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFC\x00": SASIndex.subheader_counts_index,
130+
b"\xFD\xFF\xFF\xFF": SASIndex.column_text_index,
131+
b"\xFF\xFF\xFF\xFD": SASIndex.column_text_index,
132+
b"\xFD\xFF\xFF\xFF\xFF\xFF\xFF\xFF": SASIndex.column_text_index,
133+
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFD": SASIndex.column_text_index,
134+
b"\xFF\xFF\xFF\xFF": SASIndex.column_name_index,
135+
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF": SASIndex.column_name_index,
136+
b"\xFC\xFF\xFF\xFF": SASIndex.column_attributes_index,
137+
b"\xFF\xFF\xFF\xFC": SASIndex.column_attributes_index,
138+
b"\xFC\xFF\xFF\xFF\xFF\xFF\xFF\xFF": SASIndex.column_attributes_index,
139+
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC": SASIndex.column_attributes_index,
140+
b"\xFE\xFB\xFF\xFF": SASIndex.format_and_label_index,
141+
b"\xFF\xFF\xFB\xFE": SASIndex.format_and_label_index,
142+
b"\xFE\xFB\xFF\xFF\xFF\xFF\xFF\xFF": SASIndex.format_and_label_index,
143+
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFB\xFE": SASIndex.format_and_label_index,
144+
b"\xFE\xFF\xFF\xFF": SASIndex.column_list_index,
145+
b"\xFF\xFF\xFF\xFE": SASIndex.column_list_index,
146+
b"\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF": SASIndex.column_list_index,
147+
b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE": SASIndex.column_list_index}
148148

149149

150150
# List of frequently used SAS date and datetime formats

pandas/tests/frame/test_analytics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ def wrapper(x):
12131213
getattr(mixed, name)(axis=0)
12141214
getattr(mixed, name)(axis=1)
12151215

1216-
class NonzeroFail:
1216+
class NonzeroFail(object):
12171217

12181218
def __nonzero__(self):
12191219
raise ValueError

pandas/tests/indexing/test_panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def test_panel_getitem(self):
149149

150150
# with an object-like
151151
# GH 9140
152-
class TestObject:
152+
class TestObject(object):
153153

154154
def __str__(self):
155155
return "TestObject"

pandas/tests/io/formats/test_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ def test_pprint_pathological_object(self):
16181618
If the test fails, it at least won't hang.
16191619
"""
16201620

1621-
class A:
1621+
class A(object):
16221622
def __getitem__(self, key):
16231623
return 3 # obviously simplified
16241624

pandas/tests/io/json/test_ujson.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@ def test_decodeFromUnicode(self):
460460
def test_encodeRecursionMax(self):
461461
# 8 is the max recursion depth
462462

463-
class O2:
463+
class O2(object):
464464
member = 0
465465
pass
466466

467-
class O1:
467+
class O1(object):
468468
member = 0
469469
pass
470470

@@ -772,14 +772,14 @@ def test_dumpToFile(self):
772772
assert "[1,2,3]" == f.getvalue()
773773

774774
def test_dumpToFileLikeObject(self):
775-
class filelike:
775+
class FileLike(object):
776776

777777
def __init__(self):
778778
self.bytes = ''
779779

780780
def write(self, bytes):
781781
self.bytes += bytes
782-
f = filelike()
782+
f = FileLike()
783783
ujson.dump([1, 2, 3], f)
784784
assert "[1,2,3]" == f.bytes
785785

@@ -800,18 +800,18 @@ def test_loadFile(self):
800800
np.array([1, 2, 3, 4]), ujson.load(f, numpy=True))
801801

802802
def test_loadFileLikeObject(self):
803-
class filelike:
803+
class FileLike(object):
804804

805805
def read(self):
806806
try:
807807
self.end
808808
except AttributeError:
809809
self.end = True
810810
return "[1,2,3,4]"
811-
f = filelike()
811+
f = FileLike()
812812
assert [1, 2, 3, 4] == ujson.load(f)
813813

814-
f = filelike()
814+
f = FileLike()
815815
tm.assert_numpy_array_equal(
816816
np.array([1, 2, 3, 4]), ujson.load(f, numpy=True))
817817

@@ -837,7 +837,7 @@ def test_encodeNumericOverflow(self):
837837

838838
def test_encodeNumericOverflowNested(self):
839839
for n in range(0, 100):
840-
class Nested:
840+
class Nested(object):
841841
x = 12839128391289382193812939
842842

843843
nested = Nested()
@@ -886,7 +886,7 @@ def test_decodeBigEscape(self):
886886
def test_toDict(self):
887887
d = {u("key"): 31337}
888888

889-
class DictTest:
889+
class DictTest(object):
890890

891891
def toDict(self):
892892
return d

pandas/tests/scalar/timedelta/test_timedelta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_ops_error_str(self):
3737
assert left != right
3838

3939
def test_ops_notimplemented(self):
40-
class Other:
40+
class Other(object):
4141
pass
4242

4343
other = Other()

pandas/tests/sparse/frame/test_frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_constructor_from_dense_series(self):
227227

228228
def test_constructor_from_unknown_type(self):
229229
# GH 19393
230-
class Unknown:
230+
class Unknown(object):
231231
pass
232232
with pytest.raises(TypeError,
233233
message='SparseDataFrame called with unknown type '

pandas/tests/test_errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_error_rename():
5454
pass
5555

5656

57-
class Foo:
57+
class Foo(object):
5858
@classmethod
5959
def classmethod(cls):
6060
raise AbstractMethodError(cls, methodtype='classmethod')

pandas/tests/test_resample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ def test_resample_how_callables(self):
10821082
def fn(x, a=1):
10831083
return str(type(x))
10841084

1085-
class fn_class:
1085+
class FnClass(object):
10861086

10871087
def __call__(self, x):
10881088
return str(type(x))
@@ -1091,7 +1091,7 @@ def __call__(self, x):
10911091
df_lambda = df.resample("M").apply(lambda x: str(type(x)))
10921092
df_partial = df.resample("M").apply(partial(fn))
10931093
df_partial2 = df.resample("M").apply(partial(fn, a=2))
1094-
df_class = df.resample("M").apply(fn_class())
1094+
df_class = df.resample("M").apply(FnClass())
10951095

10961096
assert_frame_equal(df_standard, df_lambda)
10971097
assert_frame_equal(df_standard, df_partial)

scripts/validate_docstrings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _output_header(title, width=80, char='#'):
9494
full_line=full_line, title_line=title_line)
9595

9696

97-
class Docstring:
97+
class Docstring(object):
9898
def __init__(self, method_name, method_obj):
9999
self.method_name = method_name
100100
self.method_obj = method_obj

versioneer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@
352352
import sys
353353

354354

355-
class VersioneerConfig:
355+
class VersioneerConfig(object):
356356
pass
357357

358358

0 commit comments

Comments
 (0)