CLN: replace %s syntax with .format in pandas.core.reshape (#17252) · pandas-dev/pandas@133a208 (original) (raw)

`@@ -534,28 +534,27 @@ def init(self, left, right, how='inner', on=None,

`

534

534

`'indicator option can only accept boolean or string arguments')

`

535

535

``

536

536

`if not isinstance(left, DataFrame):

`

537

``

`-

raise ValueError(

`

538

``

`-

'can not merge DataFrame with instance of '

`

539

``

`-

'type {0}'.format(type(left)))

`

``

537

`+

raise ValueError('can not merge DataFrame with instance of '

`

``

538

`+

'type {left}'.format(left=type(left)))

`

540

539

`if not isinstance(right, DataFrame):

`

541

``

`-

raise ValueError(

`

542

``

`-

'can not merge DataFrame with instance of '

`

543

``

`-

'type {0}'.format(type(right)))

`

``

540

`+

raise ValueError('can not merge DataFrame with instance of '

`

``

541

`+

'type {right}'.format(right=type(right)))

`

544

542

``

545

543

`if not is_bool(left_index):

`

546

544

`raise ValueError(

`

547

545

`'left_index parameter must be of type bool, not '

`

548

``

`-

'{0}'.format(type(left_index)))

`

``

546

`+

'{left_index}'.format(left_index=type(left_index)))

`

549

547

`if not is_bool(right_index):

`

550

548

`raise ValueError(

`

551

549

`'right_index parameter must be of type bool, not '

`

552

``

`-

'{0}'.format(type(right_index)))

`

``

550

`+

'{right_index}'.format(right_index=type(right_index)))

`

553

551

``

554

552

`# warn user when merging between different levels

`

555

553

`if left.columns.nlevels != right.columns.nlevels:

`

556

554

`msg = ('merging between different levels can give an unintended '

`

557

``

`-

'result ({0} levels on the left, {1} on the right)')

`

558

``

`-

msg = msg.format(left.columns.nlevels, right.columns.nlevels)

`

``

555

`+

'result ({left} levels on the left, {right} on the right)'

`

``

556

`+

).format(left=left.columns.nlevels,

`

``

557

`+

right=right.columns.nlevels)

`

559

558

`warnings.warn(msg, UserWarning)

`

560

559

``

561

560

`self._validate_specification()

`

`@@ -613,7 +612,8 @@ def _indicator_pre_merge(self, left, right):

`

613

612

`for i in ['_left_indicator', '_right_indicator']:

`

614

613

`if i in columns:

`

615

614

`` raise ValueError("Cannot use indicator=True option when "

``

616

``

`-

"data contains a column named {}".format(i))

`

``

615

`+

"data contains a column named {name}"

`

``

616

`+

.format(name=i))

`

617

617

`if self.indicator_name in columns:

`

618

618

`raise ValueError(

`

619

619

`"Cannot use name of an existing column for indicator column")

`

`@@ -717,7 +717,7 @@ def _maybe_add_join_keys(self, result, left_indexer, right_indexer):

`

717

717

`if name in result:

`

718

718

`result[name] = key_col

`

719

719

`else:

`

720

``

`-

result.insert(i, name or 'key_%d' % i, key_col)

`

``

720

`+

result.insert(i, name or 'key_{i}'.format(i=i), key_col)

`

721

721

``

722

722

`def _get_join_indexers(self):

`

723

723

`""" return the join indexers """

`

`@@ -952,8 +952,8 @@ def _validate_specification(self):

`

952

952

`if len(common_cols) == 0:

`

953

953

`raise MergeError('No common columns to perform merge on')

`

954

954

`if not common_cols.is_unique:

`

955

``

`-

raise MergeError("Data columns not unique: %s"

`

956

``

`-

% repr(common_cols))

`

``

955

`+

raise MergeError("Data columns not unique: {common!r}"

`

``

956

`+

.format(common=common_cols))

`

957

957

`self.left_on = self.right_on = common_cols

`

958

958

`elif self.on is not None:

`

959

959

`if self.left_on is not None or self.right_on is not None:

`

`@@ -1119,12 +1119,14 @@ def get_result(self):

`

1119

1119

``

1120

1120

``

1121

1121

`def _asof_function(direction, on_type):

`

1122

``

`-

return getattr(libjoin, 'asof_join_%s_%s' % (direction, on_type), None)

`

``

1122

`+

name = 'asof_join_{dir}_{on}'.format(dir=direction, on=on_type)

`

``

1123

`+

return getattr(libjoin, name, None)

`

1123

1124

``

1124

1125

``

1125

1126

`def _asof_by_function(direction, on_type, by_type):

`

1126

``

`-

return getattr(libjoin, 'asof_join_%s_%s_by_%s' %

`

1127

``

`-

(direction, on_type, by_type), None)

`

``

1127

`+

name = 'asof_join_{dir}_{on}by{by}'.format(

`

``

1128

`+

dir=direction, on=on_type, by=by_type)

`

``

1129

`+

return getattr(libjoin, name, None)

`

1128

1130

``

1129

1131

``

1130

1132

`_type_casters = {

`

`@@ -1153,7 +1155,7 @@ def _get_cython_type(dtype):

`

1153

1155

`type_name = _get_dtype(dtype).name

`

1154

1156

`ctype = _cython_types.get(type_name, 'object')

`

1155

1157

`if ctype == 'error':

`

1156

``

`-

raise MergeError('unsupported type: ' + type_name)

`

``

1158

`+

raise MergeError('unsupported type: {type}'.format(type=type_name))

`

1157

1159

`return ctype

`

1158

1160

``

1159

1161

``

`@@ -1235,7 +1237,8 @@ def _validate_specification(self):

`

1235

1237

``

1236

1238

`# check 'direction' is valid

`

1237

1239

`if self.direction not in ['backward', 'forward', 'nearest']:

`

1238

``

`-

raise MergeError('direction invalid: ' + self.direction)

`

``

1240

`+

raise MergeError('direction invalid: {direction}'

`

``

1241

`+

.format(direction=self.direction))

`

1239

1242

``

1240

1243

`@property

`

1241

1244

`def _asof_key(self):

`

`@@ -1264,7 +1267,7 @@ def _get_merge_keys(self):

`

1264

1267

`lt = left_join_keys[-1]

`

1265

1268

``

1266

1269

`msg = "incompatible tolerance, must be compat " \

`

1267

``

`-

"with type {0}".format(type(lt))

`

``

1270

`+

"with type {lt}".format(lt=type(lt))

`

1268

1271

``

1269

1272

`if is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt):

`

1270

1273

`if not isinstance(self.tolerance, Timedelta):

`

`@@ -1283,8 +1286,8 @@ def _get_merge_keys(self):

`

1283

1286

``

1284

1287

`# validate allow_exact_matches

`

1285

1288

`if not is_bool(self.allow_exact_matches):

`

1286

``

`-

raise MergeError("allow_exact_matches must be boolean, "

`

1287

``

`-

"passed {0}".format(self.allow_exact_matches))

`

``

1289

`+

msg = "allow_exact_matches must be boolean, passed {passed}"

`

``

1290

`+

raise MergeError(msg.format(passed=self.allow_exact_matches))

`

1288

1291

``

1289

1292

`return left_join_keys, right_join_keys, join_names

`

1290

1293

``

`@@ -1306,11 +1309,11 @@ def flip(xs):

`

1306

1309

`tolerance = self.tolerance

`

1307

1310

``

1308

1311

`# we required sortedness in the join keys

`

1309

``

`-

msg = " keys must be sorted"

`

``

1312

`+

msg = "{side} keys must be sorted"

`

1310

1313

`if not Index(left_values).is_monotonic:

`

1311

``

`-

raise ValueError('left' + msg)

`

``

1314

`+

raise ValueError(msg.format(side='left'))

`

1312

1315

`if not Index(right_values).is_monotonic:

`

1313

``

`-

raise ValueError('right' + msg)

`

``

1316

`+

raise ValueError(msg.format(side='right'))

`

1314

1317

``

1315

1318

`# initial type conversion as needed

`

1316

1319

`if needs_i8_conversion(left_values):

`