Skip to content

Commit ea6cad0

Browse files
committed
CLN: Remove redundant int() calls
1 parent d642b67 commit ea6cad0

File tree

21 files changed

+32
-34
lines changed

21 files changed

+32
-34
lines changed

asv_bench/benchmarks/arithmetic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ def setup(self, op):
122122
n_rows = 500
123123

124124
# construct dataframe with 2 blocks
125-
arr1 = np.random.randn(n_rows, int(n_cols / 2)).astype("f8")
126-
arr2 = np.random.randn(n_rows, int(n_cols / 2)).astype("f4")
125+
arr1 = np.random.randn(n_rows, n_cols // 2).astype("f8")
126+
arr2 = np.random.randn(n_rows, n_cols // 2).astype("f4")
127127
df = pd.concat(
128128
[pd.DataFrame(arr1), pd.DataFrame(arr2)], axis=1, ignore_index=True
129129
)
130130
# should already be the case, but just to be sure
131131
df._consolidate_inplace()
132132

133133
# TODO: GH#33198 the setting here shoudlnt need two steps
134-
arr1 = np.random.randn(n_rows, int(n_cols / 4)).astype("f8")
135-
arr2 = np.random.randn(n_rows, int(n_cols / 2)).astype("i8")
136-
arr3 = np.random.randn(n_rows, int(n_cols / 4)).astype("f8")
134+
arr1 = np.random.randn(n_rows, n_cols // 4).astype("f8")
135+
arr2 = np.random.randn(n_rows, n_cols // 2).astype("i8")
136+
arr3 = np.random.randn(n_rows, n_cols // 4).astype("f8")
137137
df2 = pd.concat(
138138
[pd.DataFrame(arr1), pd.DataFrame(arr2), pd.DataFrame(arr3)],
139139
axis=1,

asv_bench/benchmarks/frame_methods.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Repr:
263263
def setup(self):
264264
nrows = 10000
265265
data = np.random.randn(nrows, 10)
266-
arrays = np.tile(np.random.randn(3, int(nrows / 100)), 100)
266+
arrays = np.tile(np.random.randn(3, nrows // 100), 100)
267267
idx = MultiIndex.from_arrays(arrays)
268268
self.df3 = DataFrame(data, index=idx)
269269
self.df4 = DataFrame(data, index=np.random.randn(nrows))
@@ -648,9 +648,9 @@ class Describe:
648648
def setup(self):
649649
self.df = DataFrame(
650650
{
651-
"a": np.random.randint(0, 100, int(1e6)),
652-
"b": np.random.randint(0, 100, int(1e6)),
653-
"c": np.random.randint(0, 100, int(1e6)),
651+
"a": np.random.randint(0, 100, 10 ** 6),
652+
"b": np.random.randint(0, 100, 10 ** 6),
653+
"c": np.random.randint(0, 100, 10 ** 6),
654654
}
655655
)
656656

asv_bench/benchmarks/inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ToNumericDowncast:
4242
]
4343

4444
N = 500000
45-
N2 = int(N / 2)
45+
N2 = N // 2
4646

4747
data_dict = {
4848
"string-int": ["1"] * N2 + [2] * N2,

asv_bench/benchmarks/rolling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class PeakMemFixedWindowMinMax:
171171
params = ["min", "max"]
172172

173173
def setup(self, operation):
174-
N = int(1e6)
174+
N = 10 ** 6
175175
arr = np.random.random(N)
176176
self.roll = pd.Series(arr).rolling(2)
177177

@@ -233,7 +233,7 @@ class GroupbyLargeGroups:
233233

234234
def setup(self):
235235
N = 100000
236-
self.df = pd.DataFrame({"A": [1, 2] * int(N / 2), "B": np.random.randn(N)})
236+
self.df = pd.DataFrame({"A": [1, 2] * (N // 2), "B": np.random.randn(N)})
237237

238238
def time_rolling_multiindex_creation(self):
239239
self.df.groupby("A").rolling(3).mean()

asv_bench/benchmarks/series_methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def time_dir_strings(self):
284284
class SeriesGetattr:
285285
# https://github.com/pandas-dev/pandas/issues/19764
286286
def setup(self):
287-
self.s = Series(1, index=date_range("2012-01-01", freq="s", periods=int(1e6)))
287+
self.s = Series(1, index=date_range("2012-01-01", freq="s", periods=10 ** 6))
288288

289289
def time_series_datetimeindex_repr(self):
290290
getattr(self.s, "a", None)

asv_bench/benchmarks/timeseries.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def time_iso8601_tz_spaceformat(self):
346346
class ToDatetimeNONISO8601:
347347
def setup(self):
348348
N = 10000
349-
half = int(N / 2)
349+
half = N // 2
350350
ts_string_1 = "March 1, 2018 12:00:00+0400"
351351
ts_string_2 = "March 1, 2018 12:00:00+0500"
352352
self.same_offset = [ts_string_1] * N
@@ -376,7 +376,7 @@ def setup(self):
376376
self.same_offset = ["10/11/2018 00:00:00.045-07:00"] * N
377377
self.diff_offset = [
378378
f"10/11/2018 00:00:00.045-0{offset}:00" for offset in range(10)
379-
] * int(N / 10)
379+
] * (N // 10)
380380

381381
def time_exact(self):
382382
to_datetime(self.s2, format="%d%b%y")

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def _create_missing_idx(nrows, ncols, density, random_state=None):
901901
random_state = np.random.RandomState(random_state)
902902

903903
# below is cribbed from scipy.sparse
904-
size = int(np.round((1 - density) * nrows * ncols))
904+
size = round((1 - density) * nrows * ncols)
905905
# generate a few more to ensure unique values
906906
min_rows = 5
907907
fac = 1.02

pandas/core/arrays/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def __iter__(self):
572572
data = self.asi8
573573
length = len(self)
574574
chunksize = 10000
575-
chunks = int(length / chunksize) + 1
575+
chunks = (length // chunksize) + 1
576576
for i in range(chunks):
577577
start_i = i * chunksize
578578
end_i = min((i + 1) * chunksize, length)

pandas/core/arrays/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def __iter__(self):
338338
data = self.asi8
339339
length = len(self)
340340
chunksize = 10000
341-
chunks = int(length / chunksize) + 1
341+
chunks = (length // chunksize) + 1
342342
for i in range(chunks):
343343
start_i = i * chunksize
344344
end_i = min((i + 1) * chunksize, length)

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5336,7 +5336,7 @@ def sample(
53365336
elif n is not None and frac is None and n % 1 != 0:
53375337
raise ValueError("Only integers accepted as `n` values")
53385338
elif n is None and frac is not None:
5339-
n = int(round(frac * axis_length))
5339+
n = round(frac * axis_length)
53405340
elif n is not None and frac is not None:
53415341
raise ValueError("Please enter a value for `frac` OR `n`, not both")
53425342

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def should_cache(
122122
return False
123123

124124
if len(arg) <= 5000:
125-
check_count = int(len(arg) * 0.1)
125+
check_count = len(arg) // 10
126126
else:
127127
check_count = 500
128128
else:

pandas/io/formats/csvs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def _generate_multiindex_header_rows(self) -> Iterator[List[Label]]:
282282

283283
def _save_body(self) -> None:
284284
nrows = len(self.data_index)
285-
chunks = int(nrows / self.chunksize) + 1
285+
chunks = (nrows // self.chunksize) + 1
286286
for i in range(chunks):
287287
start_i = i * self.chunksize
288288
end_i = min(start_i + self.chunksize, nrows)

pandas/io/formats/string.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _fit_strcols_to_terminal_width(self, strcols: List[List[str]]) -> str:
160160
counter = 0
161161
while adj_dif > 0 and n_cols > 1:
162162
counter += 1
163-
mid = int(round(n_cols / 2.0))
163+
mid = round(n_cols / 2)
164164
mid_ix = col_lens.index[mid]
165165
col_len = col_lens[mid_ix]
166166
# adjoin adds one

pandas/io/sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def insert(self, chunksize: Optional[int] = None, method: Optional[str] = None):
905905
elif chunksize == 0:
906906
raise ValueError("chunksize argument should be non-zero")
907907

908-
chunks = int(nrows / chunksize) + 1
908+
chunks = (nrows // chunksize) + 1
909909

910910
with self.pd_sql.run_transaction() as conn:
911911
for i in range(chunks):

pandas/plotting/_matplotlib/converter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def __call__(self, x, pos=0) -> str:
182182
"""
183183
fmt = "%H:%M:%S.%f"
184184
s = int(x)
185-
msus = int(round((x - s) * 1e6))
185+
msus = round((x - s) * 1e6)
186186
ms = msus // 1000
187187
us = msus % 1000
188188
m, s = divmod(s, 60)

pandas/plotting/_matplotlib/tools.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ def _get_layout(nplots: int, layout=None, layout_type: str = "box") -> Tuple[int
6161

6262
nrows, ncols = layout
6363

64-
# Python 2 compat
65-
ceil_ = lambda x: int(ceil(x))
6664
if nrows == -1 and ncols > 0:
67-
layout = nrows, ncols = (ceil_(float(nplots) / ncols), ncols)
65+
layout = nrows, ncols = (ceil(nplots / ncols), ncols)
6866
elif ncols == -1 and nrows > 0:
69-
layout = nrows, ncols = (nrows, ceil_(float(nplots) / nrows))
67+
layout = nrows, ncols = (nrows, ceil(nplots / nrows))
7068
elif ncols <= 0 and nrows <= 0:
7169
msg = "At least one dimension of layout must be positive"
7270
raise ValueError(msg)

pandas/tests/generic/test_generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,14 @@ def test_truncate_out_of_bounds(self):
305305
# GH11382
306306

307307
# small
308-
shape = [int(2e3)] + ([1] * (self._ndim - 1))
308+
shape = [2000] + ([1] * (self._ndim - 1))
309309
small = self._construct(shape, dtype="int8", value=1)
310310
self._compare(small.truncate(), small)
311311
self._compare(small.truncate(before=0, after=3e3), small)
312312
self._compare(small.truncate(before=-1, after=2e3), small)
313313

314314
# big
315-
shape = [int(2e6)] + ([1] * (self._ndim - 1))
315+
shape = [2_000_000] + ([1] * (self._ndim - 1))
316316
big = self._construct(shape, dtype="int8", value=1)
317317
self._compare(big.truncate(), big)
318318
self._compare(big.truncate(before=0, after=3e6), big)

pandas/tests/io/pytables/test_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,7 @@ def test_select_iterator_many_empty_frames(self, setup_path):
31643164
# GH 8014
31653165
# using iterator and where clause can return many empty
31663166
# frames.
3167-
chunksize = int(1e4)
3167+
chunksize = 10_000
31683168

31693169
# with iterator, range limited to the first chunk
31703170
with ensure_clean_store(setup_path) as store:

pandas/tests/plotting/test_datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ def test_time_musec(self):
10751075
for t, l in zip(ticks, labels):
10761076
m, s = divmod(int(t), 60)
10771077

1078-
us = int(round((t - int(t)) * 1e6))
1078+
us = round((t - int(t)) * 1e6)
10791079

10801080
h, m = divmod(m, 60)
10811081
rs = l.get_text()

pandas/tests/series/methods/test_fillna.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def test_timedelta_fillna(self, frame_or_series):
231231
expected = frame_or_series(expected)
232232
tm.assert_equal(result, expected)
233233

234-
result = obj.fillna(np.timedelta64(int(1e9)))
234+
result = obj.fillna(np.timedelta64(10 ** 9))
235235
expected = Series(
236236
[
237237
timedelta(seconds=1),

pandas/tests/tools/test_to_timedelta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_to_timedelta_float(self):
184184
# https://github.com/pandas-dev/pandas/issues/25077
185185
arr = np.arange(0, 1, 1e-6)[-10:]
186186
result = pd.to_timedelta(arr, unit="s")
187-
expected_asi8 = np.arange(999990000, int(1e9), 1000, dtype="int64")
187+
expected_asi8 = np.arange(999990000, 10 ** 9, 1000, dtype="int64")
188188
tm.assert_numpy_array_equal(result.asi8, expected_asi8)
189189

190190
def test_to_timedelta_coerce_strings_unit(self):

0 commit comments

Comments
 (0)