Skip to content

Commit f9ce9d6

Browse files
authored
Remove Python2 numeric relicts (#38916)
1 parent a5fbc41 commit f9ce9d6

34 files changed

+76
-81
lines changed

asv_bench/benchmarks/arithmetic.py

Lines changed: 5 additions & 5 deletions
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

Lines changed: 4 additions & 4 deletions
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/hash_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class Float64GroupIndex:
103103
# GH28303
104104
def setup(self):
105105
self.df = pd.date_range(
106-
start="1/1/2018", end="1/2/2018", periods=1e6
106+
start="1/1/2018", end="1/2/2018", periods=10 ** 6
107107
).to_frame()
108-
self.group_index = np.round(self.df.index.astype(int) / 1e9)
108+
self.group_index = np.round(self.df.index.astype(int) / 10 ** 9)
109109

110110
def time_groupby(self):
111111
self.df.groupby(self.group_index).last()

asv_bench/benchmarks/inference.py

Lines changed: 1 addition & 1 deletion
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/join_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def setup(self):
158158
daily_dates = date_index.to_period("D").to_timestamp("S", "S")
159159
self.fracofday = date_index.values - daily_dates.values
160160
self.fracofday = self.fracofday.astype("timedelta64[ns]")
161-
self.fracofday = self.fracofday.astype(np.float64) / 86400000000000.0
161+
self.fracofday = self.fracofday.astype(np.float64) / 86_400_000_000_000
162162
self.fracofday = Series(self.fracofday, daily_dates)
163163
index = date_range(date_index.min(), date_index.max(), freq="D")
164164
self.temp = Series(1.0, index)[self.fracofday.index]

asv_bench/benchmarks/rolling.py

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def value_counts(
835835
result = result.sort_values(ascending=ascending)
836836

837837
if normalize:
838-
result = result / float(counts.sum())
838+
result = result / counts.sum()
839839

840840
return result
841841

0 commit comments

Comments
 (0)