Skip to content

Commit 529f7ca

Browse files
authored
Upgrade python syntax with pyupgrade (onnx#4212)
1 parent fdd8902 commit 529f7ca

File tree

100 files changed

+813
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+813
-867
lines changed

docs/Operators.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,9 +2538,9 @@ for from_type, to_type in test_cases:
25382538
input_type_proto = None
25392539
output_type_proto = None
25402540
if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:
2541-
np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
2542-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
2543-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)
2541+
np_fp32 = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
2542+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
2543+
'NaN', 'INF', '+INF', '-INF'], dtype=np.float32)
25442544
little_endisan = sys.byteorder == 'little'
25452545
np_uint16_view = np_fp32.view(dtype=np.uint16)
25462546
np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]
@@ -2578,9 +2578,9 @@ for from_type, to_type in test_cases:
25782578
else:
25792579
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
25802580
else:
2581-
input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
2582-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
2583-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4])
2581+
input = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
2582+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
2583+
'NaN', 'INF', '+INF', '-INF'], dtype=np.dtype(object)).reshape([3, 4])
25842584
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
25852585
node = onnx.helper.make_node(
25862586
'Cast',
@@ -2661,9 +2661,9 @@ for from_type, to_type in test_cases:
26612661
input_type_proto = None
26622662
output_type_proto = None
26632663
if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:
2664-
np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
2665-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
2666-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)
2664+
np_fp32 = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
2665+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
2666+
'NaN', 'INF', '+INF', '-INF'], dtype=np.float32)
26672667
little_endisan = sys.byteorder == 'little'
26682668
np_uint16_view = np_fp32.view(dtype=np.uint16)
26692669
np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]
@@ -2701,9 +2701,9 @@ for from_type, to_type in test_cases:
27012701
else:
27022702
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
27032703
else:
2704-
input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
2705-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
2706-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(np.object)).reshape([3, 4])
2704+
input = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
2705+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
2706+
'NaN', 'INF', '+INF', '-INF'], dtype=np.dtype(np.object)).reshape([3, 4])
27072707
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
27082708
like = output.flatten()[0:1]
27092709
node = onnx.helper.make_node(
@@ -3226,7 +3226,7 @@ Other versions of this operator: <a href="Changelog.md#Concat-1">1</a>, <a href=
32263226
<summary>concat</summary>
32273227

32283228
```python
3229-
test_cases: Dict[Text, Sequence[Any]] = {
3229+
test_cases: Dict[str, Sequence[Any]] = {
32303230
'1d': ([1, 2],
32313231
[3, 4]),
32323232
'2d': ([[1, 2], [3, 4]],
@@ -11226,7 +11226,7 @@ for op_dtype in all_numeric_dtypes:
1122611226
outputs=['result'],
1122711227
)
1122811228
expect(node, inputs=[data_0, data_1], outputs=[result],
11229-
name='test_max_{0}'.format(np.dtype(op_dtype).name))
11229+
name=f'test_max_{np.dtype(op_dtype).name}')
1123011230
```
1123111231

1123211232
</details>
@@ -12335,7 +12335,7 @@ for op_dtype in all_numeric_dtypes:
1233512335
outputs=['result'],
1233612336
)
1233712337
expect(node, inputs=[data_0, data_1], outputs=[result],
12338-
name='test_min_{0}'.format(np.dtype(op_dtype).name))
12338+
name=f'test_min_{np.dtype(op_dtype).name}')
1233912339
```
1234012340

1234112341
</details>
@@ -14691,7 +14691,7 @@ for mode in ['edge', 'reflect']:
1469114691
)
1469214692

1469314693
expect(node, inputs=[x, pads], outputs=[y],
14694-
name='test_{}_pad'.format(mode))
14694+
name=f'test_{mode}_pad')
1469514695
```
1469614696

1469714697
</details>
@@ -19199,8 +19199,8 @@ This version of the operator has been available since version 17 of the default
1919919199

1920019200
```python
1920119201
signal = np.arange(0, 128, dtype=np.float32).reshape(1, 128, 1)
19202-
length = np.array((16)).astype(np.int64)
19203-
step = np.array((8)).astype(np.int64)
19202+
length = np.array(16).astype(np.int64)
19203+
step = np.array(8).astype(np.int64)
1920419204

1920519205
no_window = "" # optional input, not supplied
1920619206
node = onnx.helper.make_node(
@@ -23373,9 +23373,9 @@ This version of the operator has been available since version 10 of the default
2337323373
<summary>monday_casesensintive_lower</summary>
2337423374

2337523375
```python
23376-
input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)
23377-
output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object)
23378-
stopwords = [u'monday']
23376+
input = np.array(['monday', 'tuesday', 'wednesday', 'thursday']).astype(object)
23377+
output = np.array(['tuesday', 'wednesday', 'thursday']).astype(object)
23378+
stopwords = ['monday']
2337923379

2338023380
node = onnx.helper.make_node(
2338123381
'StringNormalizer',
@@ -23395,9 +23395,9 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
2339523395
<summary>monday_casesensintive_nochangecase</summary>
2339623396

2339723397
```python
23398-
input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)
23399-
output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object)
23400-
stopwords = [u'monday']
23398+
input = np.array(['monday', 'tuesday', 'wednesday', 'thursday']).astype(object)
23399+
output = np.array(['tuesday', 'wednesday', 'thursday']).astype(object)
23400+
stopwords = ['monday']
2340123401

2340223402
node = onnx.helper.make_node(
2340323403
'StringNormalizer',
@@ -23416,9 +23416,9 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
2341623416
<summary>monday_casesensintive_upper</summary>
2341723417

2341823418
```python
23419-
input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)
23420-
output = np.array([u'TUESDAY', u'WEDNESDAY', u'THURSDAY']).astype(object)
23421-
stopwords = [u'monday']
23419+
input = np.array(['monday', 'tuesday', 'wednesday', 'thursday']).astype(object)
23420+
output = np.array(['TUESDAY', 'WEDNESDAY', 'THURSDAY']).astype(object)
23421+
stopwords = ['monday']
2342223422

2342323423
node = onnx.helper.make_node(
2342423424
'StringNormalizer',
@@ -23438,9 +23438,9 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
2343823438
<summary>monday_empty_output</summary>
2343923439

2344023440
```python
23441-
input = np.array([u'monday', u'monday']).astype(object)
23442-
output = np.array([u'']).astype(object)
23443-
stopwords = [u'monday']
23441+
input = np.array(['monday', 'monday']).astype(object)
23442+
output = np.array(['']).astype(object)
23443+
stopwords = ['monday']
2344423444

2344523445
node = onnx.helper.make_node(
2344623446
'StringNormalizer',
@@ -23460,13 +23460,13 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
2346023460
<summary>monday_insensintive_upper_twodim</summary>
2346123461

2346223462
```python
23463-
input = np.array([u'Monday', u'tuesday', u'wednesday', u'Monday', u'tuesday', u'wednesday']).astype(object).reshape([1, 6])
23463+
input = np.array(['Monday', 'tuesday', 'wednesday', 'Monday', 'tuesday', 'wednesday']).astype(object).reshape([1, 6])
2346423464

2346523465
# It does upper case cecedille, accented E
2346623466
# and german umlaut but fails
2346723467
# with german eszett
23468-
output = np.array([u'TUESDAY', u'WEDNESDAY', u'TUESDAY', u'WEDNESDAY']).astype(object).reshape([1, 4])
23469-
stopwords = [u'monday']
23468+
output = np.array(['TUESDAY', 'WEDNESDAY', 'TUESDAY', 'WEDNESDAY']).astype(object).reshape([1, 4])
23469+
stopwords = ['monday']
2347023470

2347123471
node = onnx.helper.make_node(
2347223472
'StringNormalizer',
@@ -23485,7 +23485,7 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
2348523485
<summary>nostopwords_nochangecase</summary>
2348623486

2348723487
```python
23488-
input = np.array([u'monday', u'tuesday']).astype(object)
23488+
input = np.array(['monday', 'tuesday']).astype(object)
2348923489
output = input
2349023490

2349123491
# No stopwords. This is a NOOP

docs/TestCoverage.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,9 @@ for from_type, to_type in test_cases:
16791679
input_type_proto = None
16801680
output_type_proto = None
16811681
if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:
1682-
np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
1683-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
1684-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)
1682+
np_fp32 = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
1683+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
1684+
'NaN', 'INF', '+INF', '-INF'], dtype=np.float32)
16851685
little_endisan = sys.byteorder == 'little'
16861686
np_uint16_view = np_fp32.view(dtype=np.uint16)
16871687
np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]
@@ -1719,9 +1719,9 @@ for from_type, to_type in test_cases:
17191719
else:
17201720
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
17211721
else:
1722-
input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
1723-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
1724-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4])
1722+
input = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
1723+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
1724+
'NaN', 'INF', '+INF', '-INF'], dtype=np.dtype(object)).reshape([3, 4])
17251725
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
17261726
node = onnx.helper.make_node(
17271727
'Cast',
@@ -1766,9 +1766,9 @@ for from_type, to_type in test_cases:
17661766
input_type_proto = None
17671767
output_type_proto = None
17681768
if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:
1769-
np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
1770-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
1771-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)
1769+
np_fp32 = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
1770+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
1771+
'NaN', 'INF', '+INF', '-INF'], dtype=np.float32)
17721772
little_endisan = sys.byteorder == 'little'
17731773
np_uint16_view = np_fp32.view(dtype=np.uint16)
17741774
np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]
@@ -1806,9 +1806,9 @@ for from_type, to_type in test_cases:
18061806
else:
18071807
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
18081808
else:
1809-
input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',
1810-
u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',
1811-
u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(np.object)).reshape([3, 4])
1809+
input = np.array(['0.47892547', '0.48033667', '0.49968487', '0.81910545',
1810+
'0.47031248', '0.816468', '0.21087195', '0.7229038',
1811+
'NaN', 'INF', '+INF', '-INF'], dtype=np.dtype(np.object)).reshape([3, 4])
18121812
output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])
18131813
like = output.flatten()[0:1]
18141814
node = onnx.helper.make_node(
@@ -2121,7 +2121,7 @@ There are 1 test cases, listed as following:
21212121
<summary>concat</summary>
21222122

21232123
```python
2124-
test_cases: Dict[Text, Sequence[Any]] = {
2124+
test_cases: Dict[str, Sequence[Any]] = {
21252125
'1d': ([1, 2],
21262126
[3, 4]),
21272127
'2d': ([[1, 2], [3, 4]],
@@ -6844,7 +6844,7 @@ for op_dtype in all_numeric_dtypes:
68446844
outputs=['result'],
68456845
)
68466846
expect(node, inputs=[data_0, data_1], outputs=[result],
6847-
name='test_max_{0}'.format(np.dtype(op_dtype).name))
6847+
name=f'test_max_{np.dtype(op_dtype).name}')
68486848
```
68496849

68506850
</details>
@@ -7565,7 +7565,7 @@ for op_dtype in all_numeric_dtypes:
75657565
outputs=['result'],
75667566
)
75677567
expect(node, inputs=[data_0, data_1], outputs=[result],
7568-
name='test_min_{0}'.format(np.dtype(op_dtype).name))
7568+
name=f'test_min_{np.dtype(op_dtype).name}')
75697569
```
75707570

75717571
</details>
@@ -9171,7 +9171,7 @@ for mode in ['edge', 'reflect']:
91719171
)
91729172

91739173
expect(node, inputs=[x, pads], outputs=[y],
9174-
name='test_{}_pad'.format(mode))
9174+
name=f'test_{mode}_pad')
91759175
```
91769176

91779177
</details>
@@ -12074,8 +12074,8 @@ There are 1 test cases, listed as following:
1207412074

1207512075
```python
1207612076
signal = np.arange(0, 128, dtype=np.float32).reshape(1, 128, 1)
12077-
length = np.array((16)).astype(np.int64)
12078-
step = np.array((8)).astype(np.int64)
12077+
length = np.array(16).astype(np.int64)
12078+
step = np.array(8).astype(np.int64)
1207912079

1208012080
no_window = "" # optional input, not supplied
1208112081
node = onnx.helper.make_node(
@@ -14541,9 +14541,9 @@ There are 6 test cases, listed as following:
1454114541
<summary>monday_casesensintive_lower</summary>
1454214542

1454314543
```python
14544-
input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)
14545-
output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object)
14546-
stopwords = [u'monday']
14544+
input = np.array(['monday', 'tuesday', 'wednesday', 'thursday']).astype(object)
14545+
output = np.array(['tuesday', 'wednesday', 'thursday']).astype(object)
14546+
stopwords = ['monday']
1454714547

1454814548
node = onnx.helper.make_node(
1454914549
'StringNormalizer',
@@ -14561,9 +14561,9 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
1456114561
<summary>monday_casesensintive_nochangecase</summary>
1456214562

1456314563
```python
14564-
input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)
14565-
output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object)
14566-
stopwords = [u'monday']
14564+
input = np.array(['monday', 'tuesday', 'wednesday', 'thursday']).astype(object)
14565+
output = np.array(['tuesday', 'wednesday', 'thursday']).astype(object)
14566+
stopwords = ['monday']
1456714567

1456814568
node = onnx.helper.make_node(
1456914569
'StringNormalizer',
@@ -14580,9 +14580,9 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
1458014580
<summary>monday_casesensintive_upper</summary>
1458114581

1458214582
```python
14583-
input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)
14584-
output = np.array([u'TUESDAY', u'WEDNESDAY', u'THURSDAY']).astype(object)
14585-
stopwords = [u'monday']
14583+
input = np.array(['monday', 'tuesday', 'wednesday', 'thursday']).astype(object)
14584+
output = np.array(['TUESDAY', 'WEDNESDAY', 'THURSDAY']).astype(object)
14585+
stopwords = ['monday']
1458614586

1458714587
node = onnx.helper.make_node(
1458814588
'StringNormalizer',
@@ -14600,9 +14600,9 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
1460014600
<summary>monday_empty_output</summary>
1460114601

1460214602
```python
14603-
input = np.array([u'monday', u'monday']).astype(object)
14604-
output = np.array([u'']).astype(object)
14605-
stopwords = [u'monday']
14603+
input = np.array(['monday', 'monday']).astype(object)
14604+
output = np.array(['']).astype(object)
14605+
stopwords = ['monday']
1460614606

1460714607
node = onnx.helper.make_node(
1460814608
'StringNormalizer',
@@ -14620,13 +14620,13 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
1462014620
<summary>monday_insensintive_upper_twodim</summary>
1462114621

1462214622
```python
14623-
input = np.array([u'Monday', u'tuesday', u'wednesday', u'Monday', u'tuesday', u'wednesday']).astype(object).reshape([1, 6])
14623+
input = np.array(['Monday', 'tuesday', 'wednesday', 'Monday', 'tuesday', 'wednesday']).astype(object).reshape([1, 6])
1462414624

1462514625
# It does upper case cecedille, accented E
1462614626
# and german umlaut but fails
1462714627
# with german eszett
14628-
output = np.array([u'TUESDAY', u'WEDNESDAY', u'TUESDAY', u'WEDNESDAY']).astype(object).reshape([1, 4])
14629-
stopwords = [u'monday']
14628+
output = np.array(['TUESDAY', 'WEDNESDAY', 'TUESDAY', 'WEDNESDAY']).astype(object).reshape([1, 4])
14629+
stopwords = ['monday']
1463014630

1463114631
node = onnx.helper.make_node(
1463214632
'StringNormalizer',
@@ -14643,7 +14643,7 @@ expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_m
1464314643
<summary>nostopwords_nochangecase</summary>
1464414644

1464514645
```python
14646-
input = np.array([u'monday', u'tuesday']).astype(object)
14646+
input = np.array(['monday', 'tuesday']).astype(object)
1464714647
output = input
1464814648

1464914649
# No stopwords. This is a NOOP

0 commit comments

Comments
 (0)