diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ffcf29f47688..2d3178f9d62fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: absolufy-imports files: ^pandas/ - repo: https://github.com/python/black - rev: 21.12b0 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/codespell-project/codespell diff --git a/asv_bench/benchmarks/algorithms.py b/asv_bench/benchmarks/algorithms.py index 2e43827232ae5..0008a589ca71f 100644 --- a/asv_bench/benchmarks/algorithms.py +++ b/asv_bench/benchmarks/algorithms.py @@ -34,7 +34,7 @@ class Factorize: param_names = ["unique", "sort", "dtype"] def setup(self, unique, sort, dtype): - N = 10 ** 5 + N = 10**5 string_index = tm.makeStringIndex(N) string_arrow = None if dtype == "string[pyarrow]": @@ -74,7 +74,7 @@ class Duplicated: param_names = ["unique", "keep", "dtype"] def setup(self, unique, keep, dtype): - N = 10 ** 5 + N = 10**5 data = { "int": pd.Index(np.arange(N), dtype="int64"), "uint": pd.Index(np.arange(N), dtype="uint64"), @@ -97,7 +97,7 @@ def time_duplicated(self, unique, keep, dtype): class Hashing: def setup_cache(self): - N = 10 ** 5 + N = 10**5 df = pd.DataFrame( { @@ -145,7 +145,7 @@ class Quantile: param_names = ["quantile", "interpolation", "dtype"] def setup(self, quantile, interpolation, dtype): - N = 10 ** 5 + N = 10**5 data = { "int": np.arange(N), "uint": np.arange(N).astype(np.uint64), @@ -158,7 +158,7 @@ def time_quantile(self, quantile, interpolation, dtype): class SortIntegerArray: - params = [10 ** 3, 10 ** 5] + params = [10**3, 10**5] def setup(self, N): data = np.arange(N, dtype=float) diff --git a/asv_bench/benchmarks/algos/isin.py b/asv_bench/benchmarks/algos/isin.py index 37fa0b490bd9e..16d90b9d23741 100644 --- a/asv_bench/benchmarks/algos/isin.py +++ b/asv_bench/benchmarks/algos/isin.py @@ -49,7 +49,7 @@ def setup(self, dtype): elif dtype in ["category[object]", "category[int]"]: # Note: sizes are different in this case than others - n = 5 * 10 ** 5 + n = 5 * 10**5 sample_size = 100 arr = list(np.random.randint(0, n // 10, size=n)) @@ -174,7 +174,7 @@ class IsinWithArange: def setup(self, dtype, M, offset_factor): offset = int(M * offset_factor) - tmp = Series(np.random.randint(offset, M + offset, 10 ** 6)) + tmp = Series(np.random.randint(offset, M + offset, 10**6)) self.series = tmp.astype(dtype) self.values = np.arange(M).astype(dtype) @@ -191,8 +191,8 @@ class IsInFloat64: param_names = ["dtype", "title"] def setup(self, dtype, title): - N_many = 10 ** 5 - N_few = 10 ** 6 + N_many = 10**5 + N_few = 10**6 self.series = Series([1, 2], dtype=dtype) if title == "many_different_values": @@ -240,10 +240,10 @@ class IsInForObjects: param_names = ["series_type", "vals_type"] def setup(self, series_type, vals_type): - N_many = 10 ** 5 + N_many = 10**5 if series_type == "nans": - ser_vals = np.full(10 ** 4, np.nan) + ser_vals = np.full(10**4, np.nan) elif series_type == "short": ser_vals = np.arange(2) elif series_type == "long": @@ -254,7 +254,7 @@ def setup(self, series_type, vals_type): self.series = Series(ser_vals).astype(object) if vals_type == "nans": - values = np.full(10 ** 4, np.nan) + values = np.full(10**4, np.nan) elif vals_type == "short": values = np.arange(2) elif vals_type == "long": @@ -277,7 +277,7 @@ class IsInLongSeriesLookUpDominates: param_names = ["dtype", "MaxNumber", "series_type"] def setup(self, dtype, MaxNumber, series_type): - N = 10 ** 7 + N = 10**7 if series_type == "random_hits": array = np.random.randint(0, MaxNumber, N) @@ -304,7 +304,7 @@ class IsInLongSeriesValuesDominate: param_names = ["dtype", "series_type"] def setup(self, dtype, series_type): - N = 10 ** 7 + N = 10**7 if series_type == "random": vals = np.random.randint(0, 10 * N, N) @@ -312,7 +312,7 @@ def setup(self, dtype, series_type): vals = np.arange(N) self.values = vals.astype(dtype.lower()) - M = 10 ** 6 + 1 + M = 10**6 + 1 self.series = Series(np.arange(M)).astype(dtype) def time_isin(self, dtypes, series_type): diff --git a/asv_bench/benchmarks/arithmetic.py b/asv_bench/benchmarks/arithmetic.py index edd1132116f76..9db2e2c2a9732 100644 --- a/asv_bench/benchmarks/arithmetic.py +++ b/asv_bench/benchmarks/arithmetic.py @@ -59,7 +59,7 @@ def time_frame_op_with_scalar(self, dtype, scalar, op): class OpWithFillValue: def setup(self): # GH#31300 - arr = np.arange(10 ** 6) + arr = np.arange(10**6) df = DataFrame({"A": arr}) ser = df["A"] @@ -93,7 +93,7 @@ class MixedFrameWithSeriesAxis: param_names = ["opname"] def setup(self, opname): - arr = np.arange(10 ** 6).reshape(1000, -1) + arr = np.arange(10**6).reshape(1000, -1) df = DataFrame(arr) df["C"] = 1.0 self.df = df @@ -201,7 +201,7 @@ def teardown(self, use_numexpr, threads): class Ops2: def setup(self): - N = 10 ** 3 + N = 10**3 self.df = DataFrame(np.random.randn(N, N)) self.df2 = DataFrame(np.random.randn(N, N)) @@ -258,7 +258,7 @@ class Timeseries: param_names = ["tz"] def setup(self, tz): - N = 10 ** 6 + N = 10**6 halfway = (N // 2) - 1 self.s = Series(date_range("20010101", periods=N, freq="T", tz=tz)) self.ts = self.s[halfway] @@ -280,7 +280,7 @@ def time_timestamp_ops_diff_with_shift(self, tz): class IrregularOps: def setup(self): - N = 10 ** 5 + N = 10**5 idx = date_range(start="1/1/2000", periods=N, freq="s") s = Series(np.random.randn(N), index=idx) self.left = s.sample(frac=1) @@ -304,7 +304,7 @@ class CategoricalComparisons: param_names = ["op"] def setup(self, op): - N = 10 ** 5 + N = 10**5 self.cat = pd.Categorical(list("aabbcd") * N, ordered=True) def time_categorical_op(self, op): @@ -317,7 +317,7 @@ class IndexArithmetic: param_names = ["dtype"] def setup(self, dtype): - N = 10 ** 6 + N = 10**6 indexes = {"int": "makeIntIndex", "float": "makeFloatIndex"} self.index = getattr(tm, indexes[dtype])(N) @@ -343,7 +343,7 @@ class NumericInferOps: param_names = ["dtype"] def setup(self, dtype): - N = 5 * 10 ** 5 + N = 5 * 10**5 self.df = DataFrame( {"A": np.arange(N).astype(dtype), "B": np.arange(N).astype(dtype)} ) @@ -367,7 +367,7 @@ def time_modulo(self, dtype): class DateInferOps: # from GH 7332 def setup_cache(self): - N = 5 * 10 ** 5 + N = 5 * 10**5 df = DataFrame({"datetime64": np.arange(N).astype("datetime64[ms]")}) df["timedelta"] = df["datetime64"] - df["datetime64"] return df @@ -388,7 +388,7 @@ class AddOverflowScalar: param_names = ["scalar"] def setup(self, scalar): - N = 10 ** 6 + N = 10**6 self.arr = np.arange(N) def time_add_overflow_scalar(self, scalar): @@ -397,7 +397,7 @@ def time_add_overflow_scalar(self, scalar): class AddOverflowArray: def setup(self): - N = 10 ** 6 + N = 10**6 self.arr = np.arange(N) self.arr_rev = np.arange(-N, 0) self.arr_mixed = np.array([1, -1]).repeat(N / 2) diff --git a/asv_bench/benchmarks/categoricals.py b/asv_bench/benchmarks/categoricals.py index 268f25c3d12e3..2b60871cbf82b 100644 --- a/asv_bench/benchmarks/categoricals.py +++ b/asv_bench/benchmarks/categoricals.py @@ -19,7 +19,7 @@ class Constructor: def setup(self): - N = 10 ** 5 + N = 10**5 self.categories = list("abcde") self.cat_idx = pd.Index(self.categories) self.values = np.tile(self.categories, N) @@ -71,16 +71,16 @@ def time_existing_series(self): class AsType: def setup(self): - N = 10 ** 5 + N = 10**5 random_pick = np.random.default_rng().choice categories = { "str": list(string.ascii_letters), - "int": np.random.randint(2 ** 16, size=154), + "int": np.random.randint(2**16, size=154), "float": sys.maxsize * np.random.random((38,)), "timestamp": [ - pd.Timestamp(x, unit="s") for x in np.random.randint(2 ** 18, size=578) + pd.Timestamp(x, unit="s") for x in np.random.randint(2**18, size=578) ], } @@ -112,7 +112,7 @@ def astype_datetime(self): class Concat: def setup(self): - N = 10 ** 5 + N = 10**5 self.s = pd.Series(list("aabbcd") * N).astype("category") self.a = pd.Categorical(list("aabbcd") * N) @@ -148,7 +148,7 @@ class ValueCounts: param_names = ["dropna"] def setup(self, dropna): - n = 5 * 10 ** 5 + n = 5 * 10**5 arr = [f"s{i:04d}" for i in np.random.randint(0, n // 10, size=n)] self.ts = pd.Series(arr).astype("category") @@ -166,7 +166,7 @@ def time_rendering(self): class SetCategories: def setup(self): - n = 5 * 10 ** 5 + n = 5 * 10**5 arr = [f"s{i:04d}" for i in np.random.randint(0, n // 10, size=n)] self.ts = pd.Series(arr).astype("category") @@ -176,7 +176,7 @@ def time_set_categories(self): class RemoveCategories: def setup(self): - n = 5 * 10 ** 5 + n = 5 * 10**5 arr = [f"s{i:04d}" for i in np.random.randint(0, n // 10, size=n)] self.ts = pd.Series(arr).astype("category") @@ -186,7 +186,7 @@ def time_remove_categories(self): class Rank: def setup(self): - N = 10 ** 5 + N = 10**5 ncats = 100 self.s_str = pd.Series(tm.makeCategoricalIndex(N, ncats)).astype(str) @@ -241,7 +241,7 @@ def time_categorical_series_is_monotonic_decreasing(self): class Contains: def setup(self): - N = 10 ** 5 + N = 10**5 self.ci = tm.makeCategoricalIndex(N) self.c = self.ci.values self.key = self.ci.categories[0] @@ -259,7 +259,7 @@ class CategoricalSlicing: param_names = ["index"] def setup(self, index): - N = 10 ** 6 + N = 10**6 categories = ["a", "b", "c"] values = [0] * N + [1] * N + [2] * N if index == "monotonic_incr": @@ -295,7 +295,7 @@ def time_getitem_bool_array(self, index): class Indexing: def setup(self): - N = 10 ** 5 + N = 10**5 self.index = pd.CategoricalIndex(range(N), range(N)) self.series = pd.Series(range(N), index=self.index).sort_index() self.category = self.index[500] @@ -327,7 +327,7 @@ def time_sort_values(self): class SearchSorted: def setup(self): - N = 10 ** 5 + N = 10**5 self.ci = tm.makeCategoricalIndex(N).sort_values() self.c = self.ci.values self.key = self.ci.categories[1] diff --git a/asv_bench/benchmarks/ctors.py b/asv_bench/benchmarks/ctors.py index 5993b068feadf..ef8b16f376d6a 100644 --- a/asv_bench/benchmarks/ctors.py +++ b/asv_bench/benchmarks/ctors.py @@ -76,7 +76,7 @@ def setup(self, data_fmt, with_index, dtype): raise NotImplementedError( "Series constructors do not support using generators with indexes" ) - N = 10 ** 4 + N = 10**4 if dtype == "float": arr = np.random.randn(N) else: @@ -90,7 +90,7 @@ def time_series_constructor(self, data_fmt, with_index, dtype): class SeriesDtypesConstructors: def setup(self): - N = 10 ** 4 + N = 10**4 self.arr = np.random.randn(N) self.arr_str = np.array(["foo", "bar", "baz"], dtype=object) self.s = Series( @@ -114,7 +114,7 @@ def time_dtindex_from_index_with_series(self): class MultiIndexConstructor: def setup(self): - N = 10 ** 4 + N = 10**4 self.iterables = [tm.makeStringIndex(N), range(20)] def time_multiindex_from_iterables(self): diff --git a/asv_bench/benchmarks/eval.py b/asv_bench/benchmarks/eval.py index cbab9fdc9c0ba..b5442531e748a 100644 --- a/asv_bench/benchmarks/eval.py +++ b/asv_bench/benchmarks/eval.py @@ -43,7 +43,7 @@ def teardown(self, engine, threads): class Query: def setup(self): - N = 10 ** 6 + N = 10**6 halfway = (N // 2) - 1 index = pd.date_range("20010101", periods=N, freq="T") s = pd.Series(index) diff --git a/asv_bench/benchmarks/frame_ctor.py b/asv_bench/benchmarks/frame_ctor.py index eace665ba0bac..810c29ec70a6f 100644 --- a/asv_bench/benchmarks/frame_ctor.py +++ b/asv_bench/benchmarks/frame_ctor.py @@ -77,7 +77,7 @@ class FromDictwithTimestamp: param_names = ["offset"] def setup(self, offset): - N = 10 ** 3 + N = 10**3 idx = date_range(Timestamp("1/1/1900"), freq=offset, periods=N) df = DataFrame(np.random.randn(N, 10), index=idx) self.d = df.to_dict() diff --git a/asv_bench/benchmarks/frame_methods.py b/asv_bench/benchmarks/frame_methods.py index 16925b7959e6a..29ac92b15f632 100644 --- a/asv_bench/benchmarks/frame_methods.py +++ b/asv_bench/benchmarks/frame_methods.py @@ -50,7 +50,7 @@ def time_frame_fancy_lookup_all(self): class Reindex: def setup(self): - N = 10 ** 3 + N = 10**3 self.df = DataFrame(np.random.randn(N * 10, N)) self.idx = np.arange(4 * N, 7 * N) self.idx_cols = np.random.randint(0, N, N) @@ -84,7 +84,7 @@ def time_reindex_upcast(self): class Rename: def setup(self): - N = 10 ** 3 + N = 10**3 self.df = DataFrame(np.random.randn(N * 10, N)) self.idx = np.arange(4 * N, 7 * N) self.dict_idx = {k: k for k in self.idx} @@ -329,7 +329,7 @@ def time_frame_mask_floats(self): class Isnull: def setup(self): - N = 10 ** 3 + N = 10**3 self.df_no_null = DataFrame(np.random.randn(N, N)) sample = np.array([np.nan, 1.0]) @@ -497,7 +497,7 @@ def time_frame_dtypes(self): class Equals: def setup(self): - N = 10 ** 3 + N = 10**3 self.float_df = DataFrame(np.random.randn(N, N)) self.float_df_nan = self.float_df.copy() self.float_df_nan.iloc[-1, -1] = np.nan @@ -618,7 +618,7 @@ class XS: param_names = ["axis"] def setup(self, axis): - self.N = 10 ** 4 + self.N = 10**4 self.df = DataFrame(np.random.randn(self.N, self.N)) def time_frame_xs(self, axis): @@ -718,9 +718,9 @@ class Describe: def setup(self): self.df = DataFrame( { - "a": np.random.randint(0, 100, 10 ** 6), - "b": np.random.randint(0, 100, 10 ** 6), - "c": np.random.randint(0, 100, 10 ** 6), + "a": np.random.randint(0, 100, 10**6), + "b": np.random.randint(0, 100, 10**6), + "c": np.random.randint(0, 100, 10**6), } ) diff --git a/asv_bench/benchmarks/gil.py b/asv_bench/benchmarks/gil.py index ac7cd87c846d5..af2efe56c2530 100644 --- a/asv_bench/benchmarks/gil.py +++ b/asv_bench/benchmarks/gil.py @@ -55,8 +55,8 @@ class ParallelGroupbyMethods: def setup(self, threads, method): if not have_real_test_parallel: raise NotImplementedError - N = 10 ** 6 - ngroups = 10 ** 3 + N = 10**6 + ngroups = 10**3 df = DataFrame( {"key": np.random.randint(0, ngroups, size=N), "data": np.random.randn(N)} ) @@ -88,8 +88,8 @@ class ParallelGroups: def setup(self, threads): if not have_real_test_parallel: raise NotImplementedError - size = 2 ** 22 - ngroups = 10 ** 3 + size = 2**22 + ngroups = 10**3 data = Series(np.random.randint(0, ngroups, size=size)) @test_parallel(num_threads=threads) @@ -110,7 +110,7 @@ class ParallelTake1D: def setup(self, dtype): if not have_real_test_parallel: raise NotImplementedError - N = 10 ** 6 + N = 10**6 df = DataFrame({"col": np.arange(N, dtype=dtype)}) indexer = np.arange(100, len(df) - 100) @@ -133,8 +133,8 @@ class ParallelKth: def setup(self): if not have_real_test_parallel: raise NotImplementedError - N = 10 ** 7 - k = 5 * 10 ** 5 + N = 10**7 + k = 5 * 10**5 kwargs_list = [{"arr": np.random.randn(N)}, {"arr": np.random.randn(N)}] @test_parallel(num_threads=2, kwargs_list=kwargs_list) @@ -151,7 +151,7 @@ class ParallelDatetimeFields: def setup(self): if not have_real_test_parallel: raise NotImplementedError - N = 10 ** 6 + N = 10**6 self.dti = date_range("1900-01-01", periods=N, freq="T") self.period = self.dti.to_period("D") diff --git a/asv_bench/benchmarks/groupby.py b/asv_bench/benchmarks/groupby.py index ff58e382a9ba2..05dd53fc38a60 100644 --- a/asv_bench/benchmarks/groupby.py +++ b/asv_bench/benchmarks/groupby.py @@ -73,7 +73,7 @@ class Apply: params = [4, 5] def setup(self, factor): - N = 10 ** factor + N = 10**factor # two cases: # - small groups: small data (N**4) + many labels (2000) -> average group # size of 5 (-> larger overhead of slicing method) @@ -116,7 +116,7 @@ class Groups: params = ["int64_small", "int64_large", "object_small", "object_large"] def setup_cache(self): - size = 10 ** 6 + size = 10**6 data = { "int64_small": Series(np.random.randint(0, 100, size=size)), "int64_large": Series(np.random.randint(0, 10000, size=size)), @@ -160,7 +160,7 @@ class Nth: params = ["float32", "float64", "datetime", "object"] def setup(self, dtype): - N = 10 ** 5 + N = 10**5 # with datetimes (GH7555) if dtype == "datetime": values = date_range("1/1/2011", periods=N, freq="s") @@ -268,7 +268,7 @@ def time_multi_int_nunique(self, df): class AggFunctions: def setup_cache(self): - N = 10 ** 5 + N = 10**5 fac1 = np.array(["A", "B", "C"], dtype="O") fac2 = np.array(["one", "two"], dtype="O") df = DataFrame( @@ -301,7 +301,7 @@ def time_different_python_functions_singlecol(self, df): class GroupStrings: def setup(self): - n = 2 * 10 ** 5 + n = 2 * 10**5 alpha = list(map("".join, product(ascii_letters, repeat=4))) data = np.random.choice(alpha, (n // 5, 4), replace=False) data = np.repeat(data, 5, axis=0) @@ -315,7 +315,7 @@ def time_multi_columns(self): class MultiColumn: def setup_cache(self): - N = 10 ** 5 + N = 10**5 key1 = np.tile(np.arange(100, dtype=object), 1000) key2 = key1.copy() np.random.shuffle(key1) @@ -345,7 +345,7 @@ def time_col_select_numpy_sum(self, df): class Size: def setup(self): - n = 10 ** 5 + n = 10**5 offsets = np.random.randint(n, size=n).astype("timedelta64[ns]") dates = np.datetime64("now") + offsets self.df = DataFrame( @@ -582,7 +582,7 @@ class RankWithTies: ] def setup(self, dtype, tie_method): - N = 10 ** 4 + N = 10**4 if dtype == "datetime64": data = np.array([Timestamp("2011/01/01")] * N, dtype=dtype) else: @@ -640,7 +640,7 @@ def time_str_func(self, dtype, method): class Categories: def setup(self): - N = 10 ** 5 + N = 10**5 arr = np.random.random(N) data = {"a": Categorical(np.random.randint(10000, size=N)), "b": arr} self.df = DataFrame(data) @@ -682,14 +682,14 @@ class Datelike: param_names = ["grouper"] def setup(self, grouper): - N = 10 ** 4 + N = 10**4 rng_map = { "period_range": period_range, "date_range": date_range, "date_range_tz": partial(date_range, tz="US/Central"), } self.grouper = rng_map[grouper]("1900-01-01", freq="D", periods=N) - self.df = DataFrame(np.random.randn(10 ** 4, 2)) + self.df = DataFrame(np.random.randn(10**4, 2)) def time_sum(self, grouper): self.df.groupby(self.grouper).sum() @@ -798,7 +798,7 @@ class TransformEngine: params = [[True, False]] def setup(self, parallel): - N = 10 ** 3 + N = 10**3 data = DataFrame( {0: [str(i) for i in range(100)] * N, 1: list(range(100)) * N}, columns=[0, 1], @@ -841,7 +841,7 @@ class AggEngine: params = [[True, False]] def setup(self, parallel): - N = 10 ** 3 + N = 10**3 data = DataFrame( {0: [str(i) for i in range(100)] * N, 1: list(range(100)) * N}, columns=[0, 1], @@ -904,7 +904,7 @@ def function(values): class Sample: def setup(self): - N = 10 ** 3 + N = 10**3 self.df = DataFrame({"a": np.zeros(N)}) self.groups = np.arange(0, N) self.weights = np.ones(N) diff --git a/asv_bench/benchmarks/hash_functions.py b/asv_bench/benchmarks/hash_functions.py index 6703cc791493a..d9a291dc27125 100644 --- a/asv_bench/benchmarks/hash_functions.py +++ b/asv_bench/benchmarks/hash_functions.py @@ -16,9 +16,9 @@ class Float64GroupIndex: # GH28303 def setup(self): self.df = pd.date_range( - start="1/1/2018", end="1/2/2018", periods=10 ** 6 + start="1/1/2018", end="1/2/2018", periods=10**6 ).to_frame() - self.group_index = np.round(self.df.index.astype(int) / 10 ** 9) + self.group_index = np.round(self.df.index.astype(int) / 10**9) def time_groupby(self): self.df.groupby(self.group_index).last() @@ -29,8 +29,8 @@ class UniqueAndFactorizeArange: param_names = ["exponent"] def setup(self, exponent): - a = np.arange(10 ** 4, dtype="float64") - self.a2 = (a + 10 ** exponent).repeat(100) + a = np.arange(10**4, dtype="float64") + self.a2 = (a + 10**exponent).repeat(100) def time_factorize(self, exponent): pd.factorize(self.a2) @@ -43,7 +43,7 @@ class NumericSeriesIndexing: params = [ (pd.Int64Index, pd.UInt64Index, pd.Float64Index), - (10 ** 4, 10 ** 5, 5 * 10 ** 5, 10 ** 6, 5 * 10 ** 6), + (10**4, 10**5, 5 * 10**5, 10**6, 5 * 10**6), ] param_names = ["index_dtype", "N"] @@ -61,7 +61,7 @@ class NumericSeriesIndexingShuffled: params = [ (pd.Int64Index, pd.UInt64Index, pd.Float64Index), - (10 ** 4, 10 ** 5, 5 * 10 ** 5, 10 ** 6, 5 * 10 ** 6), + (10**4, 10**5, 5 * 10**5, 10**6, 5 * 10**6), ] param_names = ["index_dtype", "N"] diff --git a/asv_bench/benchmarks/index_cached_properties.py b/asv_bench/benchmarks/index_cached_properties.py index 16fbc741775e4..ad6170e256091 100644 --- a/asv_bench/benchmarks/index_cached_properties.py +++ b/asv_bench/benchmarks/index_cached_properties.py @@ -22,7 +22,7 @@ class IndexCache: param_names = ["index_type"] def setup(self, index_type): - N = 10 ** 5 + N = 10**5 if index_type == "MultiIndex": self.idx = pd.MultiIndex.from_product( [pd.date_range("1/1/2000", freq="T", periods=N // 2), ["a", "b"]] diff --git a/asv_bench/benchmarks/index_object.py b/asv_bench/benchmarks/index_object.py index 2b2302a796730..dab33f02c2cd9 100644 --- a/asv_bench/benchmarks/index_object.py +++ b/asv_bench/benchmarks/index_object.py @@ -25,7 +25,7 @@ class SetOperations: param_names = ["dtype", "method"] def setup(self, dtype, method): - N = 10 ** 5 + N = 10**5 dates_left = date_range("1/1/2000", periods=N, freq="T") fmt = "%Y-%m-%d %H:%M:%S" date_str_left = Index(dates_left.strftime(fmt)) @@ -46,7 +46,7 @@ def time_operation(self, dtype, method): class SetDisjoint: def setup(self): - N = 10 ** 5 + N = 10**5 B = N + 20000 self.datetime_left = DatetimeIndex(range(N)) self.datetime_right = DatetimeIndex(range(N, B)) @@ -57,8 +57,8 @@ def time_datetime_difference_disjoint(self): class Range: def setup(self): - self.idx_inc = RangeIndex(start=0, stop=10 ** 6, step=3) - self.idx_dec = RangeIndex(start=10 ** 6, stop=-1, step=-3) + self.idx_inc = RangeIndex(start=0, stop=10**6, step=3) + self.idx_dec = RangeIndex(start=10**6, stop=-1, step=-3) def time_max(self): self.idx_inc.max() @@ -139,7 +139,7 @@ class Indexing: param_names = ["dtype"] def setup(self, dtype): - N = 10 ** 6 + N = 10**6 self.idx = getattr(tm, f"make{dtype}Index")(N) self.array_mask = (np.arange(N) % 3) == 0 self.series_mask = Series(self.array_mask) @@ -192,7 +192,7 @@ def time_get_loc(self): class IntervalIndexMethod: # GH 24813 - params = [10 ** 3, 10 ** 5] + params = [10**3, 10**5] def setup(self, N): left = np.append(np.arange(N), np.array(0)) diff --git a/asv_bench/benchmarks/indexing.py b/asv_bench/benchmarks/indexing.py index 58f2a73d82842..1135e1ada1b78 100644 --- a/asv_bench/benchmarks/indexing.py +++ b/asv_bench/benchmarks/indexing.py @@ -37,7 +37,7 @@ class NumericSeriesIndexing: param_names = ["index_dtype", "index_structure"] def setup(self, index, index_structure): - N = 10 ** 6 + N = 10**6 indices = { "unique_monotonic_inc": index(range(N)), "nonunique_monotonic_inc": index( @@ -97,7 +97,7 @@ class NonNumericSeriesIndexing: param_names = ["index_dtype", "index_structure"] def setup(self, index, index_structure): - N = 10 ** 6 + N = 10**6 if index == "string": index = tm.makeStringIndex(N) elif index == "datetime": @@ -263,7 +263,7 @@ class CategoricalIndexIndexing: param_names = ["index"] def setup(self, index): - N = 10 ** 5 + N = 10**5 values = list("a" * N + "b" * N + "c" * N) indices = { "monotonic_incr": CategoricalIndex(values), @@ -332,7 +332,7 @@ class IndexSingleRow: param_names = ["unique_cols"] def setup(self, unique_cols): - arr = np.arange(10 ** 7).reshape(-1, 10) + arr = np.arange(10**7).reshape(-1, 10) df = DataFrame(arr) dtypes = ["u1", "u2", "u4", "u8", "i1", "i2", "i4", "i8", "f8", "f4"] for i, d in enumerate(dtypes): @@ -364,7 +364,7 @@ def time_frame_assign_timeseries_index(self): class InsertColumns: def setup(self): - self.N = 10 ** 3 + self.N = 10**3 self.df = DataFrame(index=range(self.N)) self.df2 = DataFrame(np.random.randn(self.N, 2)) diff --git a/asv_bench/benchmarks/indexing_engines.py b/asv_bench/benchmarks/indexing_engines.py index 60e07a9d1469c..0c6cb89f49da1 100644 --- a/asv_bench/benchmarks/indexing_engines.py +++ b/asv_bench/benchmarks/indexing_engines.py @@ -36,7 +36,7 @@ class NumericEngineIndexing: _get_numeric_engines(), ["monotonic_incr", "monotonic_decr", "non_monotonic"], [True, False], - [10 ** 5, 2 * 10 ** 6], # 2e6 is above SIZE_CUTOFF + [10**5, 2 * 10**6], # 2e6 is above SIZE_CUTOFF ] param_names = ["engine_and_dtype", "index_type", "unique", "N"] @@ -86,7 +86,7 @@ class ObjectEngineIndexing: param_names = ["index_type"] def setup(self, index_type): - N = 10 ** 5 + N = 10**5 values = list("a" * N + "b" * N + "c" * N) arr = { "monotonic_incr": np.array(values, dtype=object), diff --git a/asv_bench/benchmarks/inference.py b/asv_bench/benchmarks/inference.py index a5a7bc5b5c8bd..0bbb599f2b045 100644 --- a/asv_bench/benchmarks/inference.py +++ b/asv_bench/benchmarks/inference.py @@ -85,8 +85,8 @@ class MaybeConvertNumeric: # go in benchmarks/libs.py def setup_cache(self): - N = 10 ** 6 - arr = np.repeat([2 ** 63], N) + np.arange(N).astype("uint64") + N = 10**6 + arr = np.repeat([2**63], N) + np.arange(N).astype("uint64") data = arr.astype(object) data[1::2] = arr[1::2].astype(str) data[-1] = -1 @@ -101,7 +101,7 @@ class MaybeConvertObjects: # does have some run-time imports from outside of _libs def setup(self): - N = 10 ** 5 + N = 10**5 data = list(range(N)) data[0] = NaT diff --git a/asv_bench/benchmarks/io/csv.py b/asv_bench/benchmarks/io/csv.py index 0b443b29116a2..10aef954a3475 100644 --- a/asv_bench/benchmarks/io/csv.py +++ b/asv_bench/benchmarks/io/csv.py @@ -266,8 +266,8 @@ def time_skipprows(self, skiprows, engine): class ReadUint64Integers(StringIORewind): def setup(self): - self.na_values = [2 ** 63 + 500] - arr = np.arange(10000).astype("uint64") + 2 ** 63 + self.na_values = [2**63 + 500] + arr = np.arange(10000).astype("uint64") + 2**63 self.data1 = StringIO("\n".join(arr.astype(str).tolist())) arr = arr.astype(object) arr[500] = -1 diff --git a/asv_bench/benchmarks/io/json.py b/asv_bench/benchmarks/io/json.py index d1468a238c491..bb09fe0ff634d 100644 --- a/asv_bench/benchmarks/io/json.py +++ b/asv_bench/benchmarks/io/json.py @@ -109,7 +109,7 @@ class ToJSON(BaseIO): param_names = ["orient", "frame"] def setup(self, orient, frame): - N = 10 ** 5 + N = 10**5 ncols = 5 index = date_range("20000101", periods=N, freq="H") timedeltas = timedelta_range(start=1, periods=N, freq="s") @@ -193,7 +193,7 @@ class ToJSONISO(BaseIO): param_names = ["orient"] def setup(self, orient): - N = 10 ** 5 + N = 10**5 index = date_range("20000101", periods=N, freq="H") timedeltas = timedelta_range(start=1, periods=N, freq="s") datetimes = date_range(start=1, periods=N, freq="s") @@ -216,7 +216,7 @@ class ToJSONLines(BaseIO): fname = "__test__.json" def setup(self): - N = 10 ** 5 + N = 10**5 ncols = 5 index = date_range("20000101", periods=N, freq="H") timedeltas = timedelta_range(start=1, periods=N, freq="s") diff --git a/asv_bench/benchmarks/join_merge.py b/asv_bench/benchmarks/join_merge.py index ad40adc75c567..dc9b1f501749e 100644 --- a/asv_bench/benchmarks/join_merge.py +++ b/asv_bench/benchmarks/join_merge.py @@ -226,7 +226,7 @@ class I8Merge: param_names = ["how"] def setup(self, how): - low, high, n = -1000, 1000, 10 ** 6 + low, high, n = -1000, 1000, 10**6 self.left = DataFrame( np.random.randint(low, high, (n, 7)), columns=list("ABCDEFG") ) @@ -394,8 +394,8 @@ def time_multiby(self, direction, tolerance): class Align: def setup(self): - size = 5 * 10 ** 5 - rng = np.arange(0, 10 ** 13, 10 ** 7) + size = 5 * 10**5 + rng = np.arange(0, 10**13, 10**7) stamps = np.datetime64("now").view("i8") + rng idx1 = np.sort(np.random.choice(stamps, size, replace=False)) idx2 = np.sort(np.random.choice(stamps, size, replace=False)) diff --git a/asv_bench/benchmarks/multiindex_object.py b/asv_bench/benchmarks/multiindex_object.py index 25df5b0214959..e349ae76ba573 100644 --- a/asv_bench/benchmarks/multiindex_object.py +++ b/asv_bench/benchmarks/multiindex_object.py @@ -203,7 +203,7 @@ class SetOperations: param_names = ["index_structure", "dtype", "method"] def setup(self, index_structure, dtype, method): - N = 10 ** 5 + N = 10**5 level1 = range(1000) level2 = date_range(start="1/1/2000", periods=N // 1000) diff --git a/asv_bench/benchmarks/replace.py b/asv_bench/benchmarks/replace.py index 2a115fb0b4fe3..c4c50f5ca8eb5 100644 --- a/asv_bench/benchmarks/replace.py +++ b/asv_bench/benchmarks/replace.py @@ -9,7 +9,7 @@ class FillNa: param_names = ["inplace"] def setup(self, inplace): - N = 10 ** 6 + N = 10**6 rng = pd.date_range("1/1/2000", periods=N, freq="min") data = np.random.randn(N) data[::2] = np.nan @@ -28,10 +28,10 @@ class ReplaceDict: param_names = ["inplace"] def setup(self, inplace): - N = 10 ** 5 - start_value = 10 ** 5 + N = 10**5 + start_value = 10**5 self.to_rep = dict(enumerate(np.arange(N) + start_value)) - self.s = pd.Series(np.random.randint(N, size=10 ** 3)) + self.s = pd.Series(np.random.randint(N, size=10**3)) def time_replace_series(self, inplace): self.s.replace(self.to_rep, inplace=inplace) @@ -44,7 +44,7 @@ class ReplaceList: param_names = ["inplace"] def setup(self, inplace): - self.df = pd.DataFrame({"A": 0, "B": 0}, index=range(4 * 10 ** 7)) + self.df = pd.DataFrame({"A": 0, "B": 0}, index=range(4 * 10**7)) def time_replace_list(self, inplace): self.df.replace([np.inf, -np.inf], np.nan, inplace=inplace) @@ -60,7 +60,7 @@ class Convert: param_names = ["constructor", "replace_data"] def setup(self, constructor, replace_data): - N = 10 ** 3 + N = 10**3 data = { "Series": pd.Series(np.random.randint(N, size=N)), "DataFrame": pd.DataFrame( diff --git a/asv_bench/benchmarks/reshape.py b/asv_bench/benchmarks/reshape.py index c83cd9a925f6d..7046c8862b0d7 100644 --- a/asv_bench/benchmarks/reshape.py +++ b/asv_bench/benchmarks/reshape.py @@ -259,7 +259,7 @@ class Cut: param_names = ["bins"] def setup(self, bins): - N = 10 ** 5 + N = 10**5 self.int_series = pd.Series(np.arange(N).repeat(5)) self.float_series = pd.Series(np.random.randn(N).repeat(5)) self.timedelta_series = pd.Series( diff --git a/asv_bench/benchmarks/rolling.py b/asv_bench/benchmarks/rolling.py index 1c53d4adc8c25..d65a1a39e8bc7 100644 --- a/asv_bench/benchmarks/rolling.py +++ b/asv_bench/benchmarks/rolling.py @@ -16,7 +16,7 @@ class Methods: param_names = ["constructor", "window_kwargs", "dtype", "method"] def setup(self, constructor, window_kwargs, dtype, method): - N = 10 ** 5 + N = 10**5 window, kwargs = window_kwargs arr = (100 * np.random.random(N)).astype(dtype) obj = getattr(pd, constructor)(arr) @@ -40,7 +40,7 @@ class Apply: param_names = ["constructor", "window", "dtype", "function", "raw"] def setup(self, constructor, window, dtype, function, raw): - N = 10 ** 3 + N = 10**3 arr = (100 * np.random.random(N)).astype(dtype) self.roll = getattr(pd, constructor)(arr).rolling(window) @@ -67,7 +67,7 @@ class NumbaEngineMethods: ] def setup(self, constructor, dtype, window_kwargs, method, parallel, cols): - N = 10 ** 3 + N = 10**3 window, kwargs = window_kwargs shape = (N, cols) if cols is not None and constructor != "Series" else N arr = (100 * np.random.random(shape)).astype(dtype) @@ -107,7 +107,7 @@ class NumbaEngineApply: ] def setup(self, constructor, dtype, window_kwargs, function, parallel, cols): - N = 10 ** 3 + N = 10**3 window, kwargs = window_kwargs shape = (N, cols) if cols is not None and constructor != "Series" else N arr = (100 * np.random.random(shape)).astype(dtype) @@ -140,7 +140,7 @@ class EWMMethods: ( { "halflife": "1 Day", - "times": pd.date_range("1900", periods=10 ** 5, freq="23s"), + "times": pd.date_range("1900", periods=10**5, freq="23s"), }, "mean", ), @@ -150,7 +150,7 @@ class EWMMethods: param_names = ["constructor", "kwargs_method", "dtype"] def setup(self, constructor, kwargs_method, dtype): - N = 10 ** 5 + N = 10**5 kwargs, method = kwargs_method arr = (100 * np.random.random(N)).astype(dtype) self.method = method @@ -170,7 +170,7 @@ class VariableWindowMethods(Methods): param_names = ["constructor", "window", "dtype", "method"] def setup(self, constructor, window, dtype, method): - N = 10 ** 5 + N = 10**5 arr = (100 * np.random.random(N)).astype(dtype) index = pd.date_range("2017-01-01", periods=N, freq="5s") self.window = getattr(pd, constructor)(arr, index=index).rolling(window) @@ -186,7 +186,7 @@ class Pairwise: param_names = ["window_kwargs", "method", "pairwise"] def setup(self, kwargs_window, method, pairwise): - N = 10 ** 4 + N = 10**4 n_groups = 20 kwargs, window = kwargs_window groups = [i for _ in range(N // n_groups) for i in range(n_groups)] @@ -215,7 +215,7 @@ class Quantile: param_names = ["constructor", "window", "dtype", "percentile"] def setup(self, constructor, window, dtype, percentile, interpolation): - N = 10 ** 5 + N = 10**5 arr = np.random.random(N).astype(dtype) self.roll = getattr(pd, constructor)(arr).rolling(window) @@ -242,7 +242,7 @@ class Rank: ] def setup(self, constructor, window, dtype, percentile, ascending, method): - N = 10 ** 5 + N = 10**5 arr = np.random.random(N).astype(dtype) self.roll = getattr(pd, constructor)(arr).rolling(window) @@ -255,7 +255,7 @@ class PeakMemFixedWindowMinMax: params = ["min", "max"] def setup(self, operation): - N = 10 ** 6 + N = 10**6 arr = np.random.random(N) self.roll = pd.Series(arr).rolling(2) @@ -274,7 +274,7 @@ class ForwardWindowMethods: param_names = ["constructor", "window_size", "dtype", "method"] def setup(self, constructor, window_size, dtype, method): - N = 10 ** 5 + N = 10**5 arr = np.random.random(N).astype(dtype) indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=window_size) self.roll = getattr(pd, constructor)(arr).rolling(window=indexer) diff --git a/asv_bench/benchmarks/series_methods.py b/asv_bench/benchmarks/series_methods.py index d8578ed604ae3..b9907b5281aa7 100644 --- a/asv_bench/benchmarks/series_methods.py +++ b/asv_bench/benchmarks/series_methods.py @@ -32,7 +32,7 @@ class ToFrame: param_names = ["dtype", "name"] def setup(self, dtype, name): - arr = np.arange(10 ** 5) + arr = np.arange(10**5) ser = Series(arr, dtype=dtype) self.ser = ser @@ -61,7 +61,7 @@ class Dropna: param_names = ["dtype"] def setup(self, dtype): - N = 10 ** 6 + N = 10**6 data = { "int": np.random.randint(1, 10, N), "datetime": date_range("2000-01-01", freq="S", periods=N), @@ -94,7 +94,7 @@ class SearchSorted: param_names = ["dtype"] def setup(self, dtype): - N = 10 ** 5 + N = 10**5 data = np.array([1] * N + [2] * N + [3] * N).astype(dtype) self.s = Series(data) @@ -130,7 +130,7 @@ def time_map(self, mapper, *args, **kwargs): class Clip: - params = [50, 1000, 10 ** 5] + params = [50, 1000, 10**5] param_names = ["n"] def setup(self, n): @@ -142,7 +142,7 @@ def time_clip(self, n): class ValueCounts: - params = [[10 ** 3, 10 ** 4, 10 ** 5], ["int", "uint", "float", "object"]] + params = [[10**3, 10**4, 10**5], ["int", "uint", "float", "object"]] param_names = ["N", "dtype"] def setup(self, N, dtype): @@ -154,7 +154,7 @@ def time_value_counts(self, N, dtype): class ValueCountsObjectDropNAFalse: - params = [10 ** 3, 10 ** 4, 10 ** 5] + params = [10**3, 10**4, 10**5] param_names = ["N"] def setup(self, N): @@ -166,7 +166,7 @@ def time_value_counts(self, N): class Mode: - params = [[10 ** 3, 10 ** 4, 10 ** 5], ["int", "uint", "float", "object"]] + params = [[10**3, 10**4, 10**5], ["int", "uint", "float", "object"]] param_names = ["N", "dtype"] def setup(self, N, dtype): @@ -178,7 +178,7 @@ def time_mode(self, N, dtype): class ModeObjectDropNAFalse: - params = [10 ** 3, 10 ** 4, 10 ** 5] + params = [10**3, 10**4, 10**5] param_names = ["N"] def setup(self, N): @@ -199,7 +199,7 @@ def time_dir_strings(self): class SeriesGetattr: # https://github.com/pandas-dev/pandas/issues/19764 def setup(self): - self.s = Series(1, index=date_range("2012-01-01", freq="s", periods=10 ** 6)) + self.s = Series(1, index=date_range("2012-01-01", freq="s", periods=10**6)) def time_series_datetimeindex_repr(self): getattr(self.s, "a", None) @@ -207,7 +207,7 @@ def time_series_datetimeindex_repr(self): class All: - params = [[10 ** 3, 10 ** 6], ["fast", "slow"], ["bool", "boolean"]] + params = [[10**3, 10**6], ["fast", "slow"], ["bool", "boolean"]] param_names = ["N", "case", "dtype"] def setup(self, N, case, dtype): @@ -220,7 +220,7 @@ def time_all(self, N, case, dtype): class Any: - params = [[10 ** 3, 10 ** 6], ["fast", "slow"], ["bool", "boolean"]] + params = [[10**3, 10**6], ["fast", "slow"], ["bool", "boolean"]] param_names = ["N", "case", "dtype"] def setup(self, N, case, dtype): @@ -248,7 +248,7 @@ class NanOps: "kurt", "prod", ], - [10 ** 3, 10 ** 6], + [10**3, 10**6], ["int8", "int32", "int64", "float64", "Int64", "boolean"], ] param_names = ["func", "N", "dtype"] diff --git a/asv_bench/benchmarks/sparse.py b/asv_bench/benchmarks/sparse.py index ec704896f5726..ff6bb582e1af5 100644 --- a/asv_bench/benchmarks/sparse.py +++ b/asv_bench/benchmarks/sparse.py @@ -40,7 +40,7 @@ class SparseArrayConstructor: param_names = ["dense_proportion", "fill_value", "dtype"] def setup(self, dense_proportion, fill_value, dtype): - N = 10 ** 6 + N = 10**6 self.array = make_array(N, dense_proportion, fill_value, dtype) def time_sparse_array(self, dense_proportion, fill_value, dtype): @@ -111,7 +111,7 @@ class Arithmetic: param_names = ["dense_proportion", "fill_value"] def setup(self, dense_proportion, fill_value): - N = 10 ** 6 + N = 10**6 arr1 = make_array(N, dense_proportion, fill_value, np.int64) self.array1 = SparseArray(arr1, fill_value=fill_value) arr2 = make_array(N, dense_proportion, fill_value, np.int64) @@ -136,7 +136,7 @@ class ArithmeticBlock: param_names = ["fill_value"] def setup(self, fill_value): - N = 10 ** 6 + N = 10**6 self.arr1 = self.make_block_array( length=N, num_blocks=1000, block_size=10, fill_value=fill_value ) diff --git a/asv_bench/benchmarks/stat_ops.py b/asv_bench/benchmarks/stat_ops.py index 5639d6702a92c..92a78b7c2f63d 100644 --- a/asv_bench/benchmarks/stat_ops.py +++ b/asv_bench/benchmarks/stat_ops.py @@ -83,7 +83,7 @@ class Rank: param_names = ["constructor", "pct"] def setup(self, constructor, pct): - values = np.random.randn(10 ** 5) + values = np.random.randn(10**5) self.data = getattr(pd, constructor)(values) def time_rank(self, constructor, pct): diff --git a/asv_bench/benchmarks/strings.py b/asv_bench/benchmarks/strings.py index 32fbf4e6c7de3..3ac59c5883742 100644 --- a/asv_bench/benchmarks/strings.py +++ b/asv_bench/benchmarks/strings.py @@ -17,7 +17,7 @@ class Dtypes: def setup(self, dtype): try: - self.s = Series(tm.makeStringIndex(10 ** 5), dtype=dtype) + self.s = Series(tm.makeStringIndex(10**5), dtype=dtype) except ImportError: raise NotImplementedError @@ -28,7 +28,7 @@ class Construction: param_names = ["dtype"] def setup(self, dtype): - self.series_arr = tm.rands_array(nchars=10, size=10 ** 5) + self.series_arr = tm.rands_array(nchars=10, size=10**5) self.frame_arr = self.series_arr.reshape((50_000, 2)).copy() # GH37371. Testing construction of string series/frames from ExtensionArrays @@ -180,7 +180,7 @@ class Repeat: param_names = ["repeats"] def setup(self, repeats): - N = 10 ** 5 + N = 10**5 self.s = Series(tm.makeStringIndex(N)) repeat = {"int": 1, "array": np.random.randint(1, 3, N)} self.values = repeat[repeats] @@ -195,7 +195,7 @@ class Cat: param_names = ["other_cols", "sep", "na_rep", "na_frac"] def setup(self, other_cols, sep, na_rep, na_frac): - N = 10 ** 5 + N = 10**5 mask_gen = lambda: np.random.choice([True, False], N, p=[1 - na_frac, na_frac]) self.s = Series(tm.makeStringIndex(N)).where(mask_gen()) if other_cols == 0: diff --git a/asv_bench/benchmarks/timeseries.py b/asv_bench/benchmarks/timeseries.py index 5b123c7127c28..9373edadb8e90 100644 --- a/asv_bench/benchmarks/timeseries.py +++ b/asv_bench/benchmarks/timeseries.py @@ -131,7 +131,7 @@ class Iteration: param_names = ["time_index"] def setup(self, time_index): - N = 10 ** 6 + N = 10**6 if time_index is timedelta_range: self.idx = time_index(start=0, freq="T", periods=N) else: @@ -247,7 +247,7 @@ class SortIndex: param_names = ["monotonic"] def setup(self, monotonic): - N = 10 ** 5 + N = 10**5 idx = date_range(start="1/1/2000", periods=N, freq="s") self.s = Series(np.random.randn(N), index=idx) if not monotonic: diff --git a/asv_bench/benchmarks/tslibs/normalize.py b/asv_bench/benchmarks/tslibs/normalize.py index f5f7adbf63995..69732018aea9a 100644 --- a/asv_bench/benchmarks/tslibs/normalize.py +++ b/asv_bench/benchmarks/tslibs/normalize.py @@ -31,7 +31,7 @@ def setup(self, size, tz): dti = pd.date_range("2016-01-01", periods=10, tz=tz).repeat(size // 10) self.i8data = dti.asi8 - if size == 10 ** 6 and tz is tzlocal_obj: + if size == 10**6 and tz is tzlocal_obj: # tzlocal is cumbersomely slow, so skip to keep runtime in check raise NotImplementedError diff --git a/asv_bench/benchmarks/tslibs/period.py b/asv_bench/benchmarks/tslibs/period.py index 15a922da7ee76..6cb1011e3c037 100644 --- a/asv_bench/benchmarks/tslibs/period.py +++ b/asv_bench/benchmarks/tslibs/period.py @@ -130,7 +130,7 @@ class TimeDT64ArrToPeriodArr: param_names = ["size", "freq", "tz"] def setup(self, size, freq, tz): - if size == 10 ** 6 and tz is tzlocal_obj: + if size == 10**6 and tz is tzlocal_obj: # tzlocal is cumbersomely slow, so skip to keep runtime in check raise NotImplementedError diff --git a/asv_bench/benchmarks/tslibs/resolution.py b/asv_bench/benchmarks/tslibs/resolution.py index 4b52efc188bf4..44f288c7de216 100644 --- a/asv_bench/benchmarks/tslibs/resolution.py +++ b/asv_bench/benchmarks/tslibs/resolution.py @@ -40,7 +40,7 @@ class TimeResolution: param_names = ["unit", "size", "tz"] def setup(self, unit, size, tz): - if size == 10 ** 6 and tz is tzlocal_obj: + if size == 10**6 and tz is tzlocal_obj: # tzlocal is cumbersomely slow, so skip to keep runtime in check raise NotImplementedError diff --git a/asv_bench/benchmarks/tslibs/tslib.py b/asv_bench/benchmarks/tslibs/tslib.py index 180f95e7fbda5..f93ef1cef841f 100644 --- a/asv_bench/benchmarks/tslibs/tslib.py +++ b/asv_bench/benchmarks/tslibs/tslib.py @@ -41,7 +41,7 @@ gettz("Asia/Tokyo"), tzlocal_obj, ] -_sizes = [0, 1, 100, 10 ** 4, 10 ** 6] +_sizes = [0, 1, 100, 10**4, 10**6] class TimeIntsToPydatetime: @@ -57,7 +57,7 @@ def setup(self, box, size, tz): if box == "date" and tz is not None: # tz is ignored, so avoid running redundant benchmarks raise NotImplementedError # skip benchmark - if size == 10 ** 6 and tz is _tzs[-1]: + if size == 10**6 and tz is _tzs[-1]: # This is cumbersomely-slow, so skip to trim runtime raise NotImplementedError # skip benchmark diff --git a/asv_bench/benchmarks/tslibs/tz_convert.py b/asv_bench/benchmarks/tslibs/tz_convert.py index 793f43e9bbe35..803c2aaa635b0 100644 --- a/asv_bench/benchmarks/tslibs/tz_convert.py +++ b/asv_bench/benchmarks/tslibs/tz_convert.py @@ -25,7 +25,7 @@ class TimeTZConvert: param_names = ["size", "tz"] def setup(self, size, tz): - if size == 10 ** 6 and tz is tzlocal_obj: + if size == 10**6 and tz is tzlocal_obj: # tzlocal is cumbersomely slow, so skip to keep runtime in check raise NotImplementedError diff --git a/environment.yml b/environment.yml index 0a87e2b56f4cb..753e210e6066a 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - cython>=0.29.24 # code checks - - black=21.5b2 + - black=22.3.0 - cpplint - flake8=4.0.1 - flake8-bugbear=21.3.2 # used by flake8, find likely bugs diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 77e4065008804..4fa9c1aabe716 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -212,7 +212,7 @@ def _get_tol_from_less_precise(check_less_precise: bool | int) -> float: return 0.5e-5 else: # Equivalent to setting checking_less_precise= - return 0.5 * 10 ** -check_less_precise + return 0.5 * 10**-check_less_precise def _check_isinstance(left, right, cls): diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 703e67b88fec8..d0d7d6a1b8da6 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -27,7 +27,7 @@ PY39 = sys.version_info >= (3, 9) PY310 = sys.version_info >= (3, 10) PYPY = platform.python_implementation() == "PyPy" -IS64 = sys.maxsize > 2 ** 32 +IS64 = sys.maxsize > 2**32 def set_function_name(f: F, name: str, cls) -> F: diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 00d5f113e16e0..6843e4f7eeb58 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1923,8 +1923,8 @@ def to_julian_date(self) -> np.ndarray: self.hour + self.minute / 60 + self.second / 3600 - + self.microsecond / 3600 / 10 ** 6 - + self.nanosecond / 3600 / 10 ** 9 + + self.microsecond / 3600 / 10**6 + + self.nanosecond / 3600 / 10**9 ) / 24 ) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index bf2d770ee1e7f..dd106b6dbb63c 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -876,7 +876,7 @@ def register_converter_cb(key): cf.register_option( "render.max_elements", - 2 ** 18, + 2**18, styler_max_elements, validator=is_nonnegative_int, ) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 40664f178993e..9dcc1c8222791 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -1202,7 +1202,7 @@ def nanskew( adjusted = values - mean if skipna and mask is not None: np.putmask(adjusted, mask, 0) - adjusted2 = adjusted ** 2 + adjusted2 = adjusted**2 adjusted3 = adjusted2 * adjusted m2 = adjusted2.sum(axis, dtype=np.float64) m3 = adjusted3.sum(axis, dtype=np.float64) @@ -1215,7 +1215,7 @@ def nanskew( m3 = _zero_out_fperr(m3) with np.errstate(invalid="ignore", divide="ignore"): - result = (count * (count - 1) ** 0.5 / (count - 2)) * (m3 / m2 ** 1.5) + result = (count * (count - 1) ** 0.5 / (count - 2)) * (m3 / m2**1.5) dtype = values.dtype if is_float_dtype(dtype): @@ -1290,15 +1290,15 @@ def nankurt( adjusted = values - mean if skipna and mask is not None: np.putmask(adjusted, mask, 0) - adjusted2 = adjusted ** 2 - adjusted4 = adjusted2 ** 2 + adjusted2 = adjusted**2 + adjusted4 = adjusted2**2 m2 = adjusted2.sum(axis, dtype=np.float64) m4 = adjusted4.sum(axis, dtype=np.float64) with np.errstate(invalid="ignore", divide="ignore"): adj = 3 * (count - 1) ** 2 / ((count - 2) * (count - 3)) numerator = count * (count + 1) * (count - 1) * m4 - denominator = (count - 2) * (count - 3) * m2 ** 2 + denominator = (count - 2) * (count - 3) * m2**2 # floating point error # diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index 4d5b11546a42f..262cd9774f694 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -494,7 +494,7 @@ def wide_to_long( """ def get_var_names(df, stub: str, sep: str, suffix: str) -> list[str]: - regex = fr"^{re.escape(stub)}{re.escape(sep)}{suffix}$" + regex = rf"^{re.escape(stub)}{re.escape(sep)}{suffix}$" pattern = re.compile(regex) return [col for col in df.columns if pattern.match(col)] diff --git a/pandas/core/roperator.py b/pandas/core/roperator.py index e6691ddf8984e..15b16b6fa976a 100644 --- a/pandas/core/roperator.py +++ b/pandas/core/roperator.py @@ -45,7 +45,7 @@ def rdivmod(left, right): def rpow(left, right): - return right ** left + return right**left def rand_(left, right): diff --git a/pandas/io/common.py b/pandas/io/common.py index eaf6f6475ec84..0331d320725ac 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -568,7 +568,7 @@ def check_parent_directory(path: Path | str) -> None: """ parent = Path(path).parent if not parent.is_dir(): - raise OSError(fr"Cannot save file into a non-existent directory: '{parent}'") + raise OSError(rf"Cannot save file into a non-existent directory: '{parent}'") @overload diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index 5992d5d6908ce..53627cc8bd753 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -471,8 +471,8 @@ class ExcelFormatter: This is only called for body cells. """ - max_rows = 2 ** 20 - max_cols = 2 ** 14 + max_rows = 2**20 + max_cols = 2**14 def __init__( self, diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 616331bf80a44..3795fbaab9122 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1744,7 +1744,7 @@ def is_dates_only(values: np.ndarray | DatetimeArray | Index | DatetimeIndex) -> values_int = values.asi8 consider_values = values_int != iNaT - one_day_nanos = 86400 * 10 ** 9 + one_day_nanos = 86400 * 10**9 even_days = ( np.logical_and(consider_values, values_int % int(one_day_nanos) != 0).sum() == 0 ) @@ -1851,7 +1851,7 @@ def get_format_timedelta64( consider_values = values_int != iNaT - one_day_nanos = 86400 * 10 ** 9 + one_day_nanos = 86400 * 10**9 # error: Unsupported operand types for % ("ExtensionArray" and "int") not_midnight = values_int % one_day_nanos != 0 # type: ignore[operator] # error: Argument 1 to "__call__" of "ufunc" has incompatible type @@ -1962,7 +1962,7 @@ def _trim_zeros_float( necessary. """ trimmed = str_floats - number_regex = re.compile(fr"^\s*[\+-]?[0-9]+\{decimal}[0-9]*$") + number_regex = re.compile(rf"^\s*[\+-]?[0-9]+\{decimal}[0-9]*$") def is_number_with_decimal(x): return re.match(number_regex, x) is not None @@ -2079,7 +2079,7 @@ def __call__(self, num: int | float) -> str: else: prefix = f"E+{int_pow10:02d}" - mant = sign * dnum / (10 ** pow10) + mant = sign * dnum / (10**pow10) if self.accuracy is None: # pragma: no cover format_str = "{mant: g}{prefix}" diff --git a/pandas/io/parsers/python_parser.py b/pandas/io/parsers/python_parser.py index 52fa3be4ff418..04639123c5cfc 100644 --- a/pandas/io/parsers/python_parser.py +++ b/pandas/io/parsers/python_parser.py @@ -158,12 +158,12 @@ def __init__(self, f: ReadCsvBuffer[str] | list, **kwds): decimal = re.escape(self.decimal) if self.thousands is None: - regex = fr"^[\-\+]?[0-9]*({decimal}[0-9]*)?([0-9]?(E|e)\-?[0-9]+)?$" + regex = rf"^[\-\+]?[0-9]*({decimal}[0-9]*)?([0-9]?(E|e)\-?[0-9]+)?$" else: thousands = re.escape(self.thousands) regex = ( - fr"^[\-\+]?([0-9]+{thousands}|[0-9])*({decimal}[0-9]*)?" - fr"([0-9]?(E|e)\-?[0-9]+)?$" + rf"^[\-\+]?([0-9]+{thousands}|[0-9])*({decimal}[0-9]*)?" + rf"([0-9]?(E|e)\-?[0-9]+)?$" ) self.num = re.compile(regex) @@ -1209,7 +1209,7 @@ def detect_colspecs( self, infer_nrows: int = 100, skiprows: set[int] | None = None ) -> list[tuple[int, int]]: # Regex escape the delimiters - delimiters = "".join([fr"\{x}" for x in self.delimiter]) + delimiters = "".join([rf"\{x}" for x in self.delimiter]) pattern = re.compile(f"([^{delimiters}]+)") rows = self.get_rows(infer_nrows, skiprows) if not rows: diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 4a50a3dabe5e7..b4b4291af59c1 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -605,7 +605,7 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame: else: dtype = c_data[2] if c_data[2] == np.int64: # Warn if necessary - if data[col].max() >= 2 ** 53: + if data[col].max() >= 2**53: ws = precision_loss_doc.format("uint64", "float64") data[col] = data[col].astype(dtype) @@ -622,7 +622,7 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame: data[col] = data[col].astype(np.int32) else: data[col] = data[col].astype(np.float64) - if data[col].max() >= 2 ** 53 or data[col].min() <= -(2 ** 53): + if data[col].max() >= 2**53 or data[col].min() <= -(2**53): ws = precision_loss_doc.format("int64", "float64") elif dtype in (np.float32, np.float64): value = data[col].max() diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index 90d3f8d9836bf..8216374732aff 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -63,7 +63,7 @@ SEC_PER_HOUR = SEC_PER_MIN * MIN_PER_HOUR SEC_PER_DAY = SEC_PER_HOUR * HOURS_PER_DAY -MUSEC_PER_DAY = 10 ** 6 * SEC_PER_DAY +MUSEC_PER_DAY = 10**6 * SEC_PER_DAY _mpl_units = {} # Cache for units overwritten by us @@ -141,7 +141,7 @@ def deregister(): def _to_ordinalf(tm: pydt.time) -> float: - tot_sec = tm.hour * 3600 + tm.minute * 60 + tm.second + tm.microsecond / 10 ** 6 + tot_sec = tm.hour * 3600 + tm.minute * 60 + tm.second + tm.microsecond / 10**6 return tot_sec @@ -207,7 +207,7 @@ def __call__(self, x, pos=0) -> str: """ fmt = "%H:%M:%S.%f" s = int(x) - msus = round((x - s) * 10 ** 6) + msus = round((x - s) * 10**6) ms = msus // 1000 us = msus % 1000 m, s = divmod(s, 60) @@ -1084,7 +1084,7 @@ def format_timedelta_ticks(x, pos, n_decimals: int) -> str: """ Convert seconds to 'D days HH:MM:SS.F' """ - s, ns = divmod(x, 10 ** 9) + s, ns = divmod(x, 10**9) m, s = divmod(s, 60) h, m = divmod(m, 60) d, h = divmod(h, 24) @@ -1098,7 +1098,7 @@ def format_timedelta_ticks(x, pos, n_decimals: int) -> str: def __call__(self, x, pos=0) -> str: (vmin, vmax) = tuple(self.axis.get_view_interval()) - n_decimals = int(np.ceil(np.log10(100 * 10 ** 9 / abs(vmax - vmin)))) + n_decimals = int(np.ceil(np.log10(100 * 10**9 / abs(vmax - vmin)))) if n_decimals > 9: n_decimals = 9 return self.format_timedelta_ticks(x, pos, n_decimals) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 5314a61191d78..7bd90a4e4d908 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -117,7 +117,7 @@ def _get_layout(nplots: int, layout=None, layout_type: str = "box") -> tuple[int return layouts[nplots] except KeyError: k = 1 - while k ** 2 < nplots: + while k**2 < nplots: k += 1 if (k - 1) * k >= nplots: diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index b7084e2bc6dc7..3b6bdeea3b3c8 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -378,11 +378,11 @@ def test_agg_apply_evaluate_lambdas_the_same(string_series): def test_with_nested_series(datetime_series): # GH 2316 # .agg with a reducer and a transform, what to do - result = datetime_series.apply(lambda x: Series([x, x ** 2], index=["x", "x^2"])) - expected = DataFrame({"x": datetime_series, "x^2": datetime_series ** 2}) + result = datetime_series.apply(lambda x: Series([x, x**2], index=["x", "x^2"])) + expected = DataFrame({"x": datetime_series, "x^2": datetime_series**2}) tm.assert_frame_equal(result, expected) - result = datetime_series.agg(lambda x: Series([x, x ** 2], index=["x", "x^2"])) + result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"])) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index bc7a929ecaa4a..22d20d7fe2356 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -120,12 +120,12 @@ def test_numeric_cmp_string_numexpr_path(self, box_with_array): box = box_with_array xbox = box if box is not Index else np.ndarray - obj = Series(np.random.randn(10 ** 5)) + obj = Series(np.random.randn(10**5)) obj = tm.box_expected(obj, box, transpose=False) result = obj == "a" - expected = Series(np.zeros(10 ** 5, dtype=bool)) + expected = Series(np.zeros(10**5, dtype=bool)) expected = tm.box_expected(expected, xbox, transpose=False) tm.assert_equal(result, expected) @@ -231,7 +231,7 @@ def test_numeric_arr_mul_tdscalar_numexpr_path( # GH#44772 for the float64 case box = box_with_array - arr_i8 = np.arange(2 * 10 ** 4).astype(np.int64, copy=False) + arr_i8 = np.arange(2 * 10**4).astype(np.int64, copy=False) arr = arr_i8.astype(dtype, copy=False) obj = tm.box_expected(arr, box, transpose=False) @@ -676,7 +676,7 @@ def test_mul_index(self, numeric_idx): idx = numeric_idx result = idx * idx - tm.assert_index_equal(result, idx ** 2) + tm.assert_index_equal(result, idx**2) def test_mul_datelike_raises(self, numeric_idx): idx = numeric_idx @@ -775,7 +775,7 @@ def test_operators_frame(self): df = pd.DataFrame({"A": ts}) tm.assert_series_equal(ts + ts, ts + df["A"], check_names=False) - tm.assert_series_equal(ts ** ts, ts ** df["A"], check_names=False) + tm.assert_series_equal(ts**ts, ts ** df["A"], check_names=False) tm.assert_series_equal(ts < ts, ts < df["A"], check_names=False) tm.assert_series_equal(ts / ts, ts / df["A"], check_names=False) @@ -1269,7 +1269,7 @@ def test_numeric_compat2(self): # __pow__ idx = RangeIndex(0, 1000, 2) - result = idx ** 2 + result = idx**2 expected = Int64Index(idx._values) ** 2 tm.assert_index_equal(Index(result.values), expected, exact=True) @@ -1393,7 +1393,7 @@ def test_sub_multiindex_swapped_levels(): @pytest.mark.parametrize("string_size", [0, 1, 2, 5]) def test_empty_str_comparison(power, string_size): # GH 37348 - a = np.array(range(10 ** power)) + a = np.array(range(10**power)) right = pd.DataFrame(a, dtype=np.int64) left = " " * string_size diff --git a/pandas/tests/arithmetic/test_object.py b/pandas/tests/arithmetic/test_object.py index c96d7c01ec97f..e107ff6b65c0f 100644 --- a/pandas/tests/arithmetic/test_object.py +++ b/pandas/tests/arithmetic/test_object.py @@ -80,12 +80,12 @@ def test_pow_ops_object(self): # pow is weird with masking & 1, so testing here a = Series([1, np.nan, 1, np.nan], dtype=object) b = Series([1, np.nan, np.nan, 1], dtype=object) - result = a ** b - expected = Series(a.values ** b.values, dtype=object) + result = a**b + expected = Series(a.values**b.values, dtype=object) tm.assert_series_equal(result, expected) - result = b ** a - expected = Series(b.values ** a.values, dtype=object) + result = b**a + expected = Series(b.values**a.values, dtype=object) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arithmetic/test_timedelta64.py b/pandas/tests/arithmetic/test_timedelta64.py index 543531889531a..3bc38c3e38213 100644 --- a/pandas/tests/arithmetic/test_timedelta64.py +++ b/pandas/tests/arithmetic/test_timedelta64.py @@ -1474,7 +1474,7 @@ def test_tdi_mul_int_array_zerodim(self, box_with_array): def test_tdi_mul_int_array(self, box_with_array): rng5 = np.arange(5, dtype="int64") idx = TimedeltaIndex(rng5) - expected = TimedeltaIndex(rng5 ** 2) + expected = TimedeltaIndex(rng5**2) idx = tm.box_expected(idx, box_with_array) expected = tm.box_expected(expected, box_with_array) @@ -2089,10 +2089,10 @@ def test_td64arr_pow_invalid(self, scalar_td, box_with_array): # defined pattern = "operate|unsupported|cannot|not supported" with pytest.raises(TypeError, match=pattern): - scalar_td ** td1 + scalar_td**td1 with pytest.raises(TypeError, match=pattern): - td1 ** scalar_td + td1**scalar_td def test_add_timestamp_to_timedelta(): diff --git a/pandas/tests/arrays/datetimes/test_constructors.py b/pandas/tests/arrays/datetimes/test_constructors.py index e6c65499f6fcc..ed285f2389959 100644 --- a/pandas/tests/arrays/datetimes/test_constructors.py +++ b/pandas/tests/arrays/datetimes/test_constructors.py @@ -29,7 +29,7 @@ def test_only_1dim_accepted(self): def test_freq_validation(self): # GH#24623 check that invalid instances cannot be created with the # public constructor - arr = np.arange(5, dtype=np.int64) * 3600 * 10 ** 9 + arr = np.arange(5, dtype=np.int64) * 3600 * 10**9 msg = ( "Inferred frequency H from passed values does not " @@ -64,7 +64,7 @@ def test_mixing_naive_tzaware_raises(self, meth): meth(obj) def test_from_pandas_array(self): - arr = pd.array(np.arange(5, dtype=np.int64)) * 3600 * 10 ** 9 + arr = pd.array(np.arange(5, dtype=np.int64)) * 3600 * 10**9 result = DatetimeArray._from_sequence(arr)._with_freq("infer") diff --git a/pandas/tests/arrays/floating/test_arithmetic.py b/pandas/tests/arrays/floating/test_arithmetic.py index e5f67a2dce3ad..7776e00c201ac 100644 --- a/pandas/tests/arrays/floating/test_arithmetic.py +++ b/pandas/tests/arrays/floating/test_arithmetic.py @@ -51,19 +51,19 @@ def test_divide_by_zero(dtype, zero, negative): def test_pow_scalar(dtype): a = pd.array([-1, 0, 1, None, 2], dtype=dtype) - result = a ** 0 + result = a**0 expected = pd.array([1, 1, 1, 1, 1], dtype=dtype) tm.assert_extension_array_equal(result, expected) - result = a ** 1 + result = a**1 expected = pd.array([-1, 0, 1, None, 2], dtype=dtype) tm.assert_extension_array_equal(result, expected) - result = a ** pd.NA + result = a**pd.NA expected = pd.array([None, None, 1, None, None], dtype=dtype) tm.assert_extension_array_equal(result, expected) - result = a ** np.nan + result = a**np.nan # TODO np.nan should be converted to pd.NA / missing before operation? expected = FloatingArray( np.array([np.nan, np.nan, 1, np.nan, np.nan], dtype=dtype.numpy_dtype), @@ -74,19 +74,19 @@ def test_pow_scalar(dtype): # reversed a = a[1:] # Can't raise integers to negative powers. - result = 0 ** a + result = 0**a expected = pd.array([1, 0, None, 0], dtype=dtype) tm.assert_extension_array_equal(result, expected) - result = 1 ** a + result = 1**a expected = pd.array([1, 1, 1, 1], dtype=dtype) tm.assert_extension_array_equal(result, expected) - result = pd.NA ** a + result = pd.NA**a expected = pd.array([1, None, None, None], dtype=dtype) tm.assert_extension_array_equal(result, expected) - result = np.nan ** a + result = np.nan**a expected = FloatingArray( np.array([1, np.nan, np.nan, np.nan], dtype=dtype.numpy_dtype), mask=a._mask ) @@ -96,7 +96,7 @@ def test_pow_scalar(dtype): def test_pow_array(dtype): a = pd.array([0, 0, 0, 1, 1, 1, None, None, None], dtype=dtype) b = pd.array([0, 1, None, 0, 1, None, 0, 1, None], dtype=dtype) - result = a ** b + result = a**b expected = pd.array([1, 0, None, 1, 1, 1, 1, None, None], dtype=dtype) tm.assert_extension_array_equal(result, expected) diff --git a/pandas/tests/arrays/integer/test_arithmetic.py b/pandas/tests/arrays/integer/test_arithmetic.py index 273bd9e4d34d5..bbaa95c8fa5a7 100644 --- a/pandas/tests/arrays/integer/test_arithmetic.py +++ b/pandas/tests/arrays/integer/test_arithmetic.py @@ -88,19 +88,19 @@ def test_mod(dtype): def test_pow_scalar(): a = pd.array([-1, 0, 1, None, 2], dtype="Int64") - result = a ** 0 + result = a**0 expected = pd.array([1, 1, 1, 1, 1], dtype="Int64") tm.assert_extension_array_equal(result, expected) - result = a ** 1 + result = a**1 expected = pd.array([-1, 0, 1, None, 2], dtype="Int64") tm.assert_extension_array_equal(result, expected) - result = a ** pd.NA + result = a**pd.NA expected = pd.array([None, None, 1, None, None], dtype="Int64") tm.assert_extension_array_equal(result, expected) - result = a ** np.nan + result = a**np.nan expected = FloatingArray( np.array([np.nan, np.nan, 1, np.nan, np.nan], dtype="float64"), np.array([False, False, False, True, False]), @@ -110,19 +110,19 @@ def test_pow_scalar(): # reversed a = a[1:] # Can't raise integers to negative powers. - result = 0 ** a + result = 0**a expected = pd.array([1, 0, None, 0], dtype="Int64") tm.assert_extension_array_equal(result, expected) - result = 1 ** a + result = 1**a expected = pd.array([1, 1, 1, 1], dtype="Int64") tm.assert_extension_array_equal(result, expected) - result = pd.NA ** a + result = pd.NA**a expected = pd.array([1, None, None, None], dtype="Int64") tm.assert_extension_array_equal(result, expected) - result = np.nan ** a + result = np.nan**a expected = FloatingArray( np.array([1, np.nan, np.nan, np.nan], dtype="float64"), np.array([False, False, True, False]), @@ -133,7 +133,7 @@ def test_pow_scalar(): def test_pow_array(): a = pd.array([0, 0, 0, 1, 1, 1, None, None, None]) b = pd.array([0, 1, None, 0, 1, None, 0, 1, None]) - result = a ** b + result = a**b expected = pd.array([1, 0, None, 1, 1, 1, 1, None, None]) tm.assert_extension_array_equal(result, expected) diff --git a/pandas/tests/arrays/integer/test_dtypes.py b/pandas/tests/arrays/integer/test_dtypes.py index 3911b7f9bad34..2bb6e36bf57b2 100644 --- a/pandas/tests/arrays/integer/test_dtypes.py +++ b/pandas/tests/arrays/integer/test_dtypes.py @@ -217,7 +217,7 @@ def test_astype_floating(): def test_astype_dt64(): # GH#32435 - arr = pd.array([1, 2, 3, pd.NA]) * 10 ** 9 + arr = pd.array([1, 2, 3, pd.NA]) * 10**9 result = arr.astype("datetime64[ns]") diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 7484fdccf4937..56dc3363a7f52 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -81,7 +81,7 @@ class SharedTests: @pytest.fixture def arr1d(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") return arr @@ -148,7 +148,7 @@ def test_compare_categorical_dtype(self, arr1d, as_index, reverse, ordered): tm.assert_numpy_array_equal(result, ones) def test_take(self): - data = np.arange(100, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(100, dtype="i8") * 24 * 3600 * 10**9 np.random.shuffle(data) freq = None if self.array_cls is not PeriodArray else "D" @@ -170,7 +170,7 @@ def test_take(self): @pytest.mark.parametrize("fill_value", [2, 2.0, Timestamp(2021, 1, 1, 12).time]) def test_take_fill_raises(self, fill_value): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") @@ -179,7 +179,7 @@ def test_take_fill_raises(self, fill_value): arr.take([0, 1], allow_fill=True, fill_value=fill_value) def test_take_fill(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") @@ -215,7 +215,7 @@ def test_concat_same_type(self, arr1d): tm.assert_index_equal(self.index_cls(result), expected) def test_unbox_scalar(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") result = arr._unbox_scalar(arr[0]) expected = arr._data.dtype.type @@ -229,7 +229,7 @@ def test_unbox_scalar(self): arr._unbox_scalar("foo") def test_check_compatible_with(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") arr._check_compatible_with(arr[0]) @@ -237,13 +237,13 @@ def test_check_compatible_with(self): arr._check_compatible_with(NaT) def test_scalar_from_string(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") result = arr._scalar_from_string(str(arr[0])) assert result == arr[0] def test_reduce_invalid(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") msg = "does not support reduction 'not a method'" @@ -252,7 +252,7 @@ def test_reduce_invalid(self): @pytest.mark.parametrize("method", ["pad", "backfill"]) def test_fillna_method_doesnt_change_orig(self, method): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") arr[4] = NaT @@ -265,7 +265,7 @@ def test_fillna_method_doesnt_change_orig(self, method): assert arr[4] is NaT def test_searchsorted(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") # scalar @@ -415,11 +415,11 @@ def test_repr_2d(self, arr1d): assert result == expected def test_setitem(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") arr[0] = arr[1] - expected = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + expected = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 expected[0] = expected[1] tm.assert_numpy_array_equal(arr.asi8, expected) @@ -504,7 +504,7 @@ def test_setitem_categorical(self, arr1d, as_index): tm.assert_equal(arr1d, expected) def test_setitem_raises(self): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") val = arr[0] @@ -540,7 +540,7 @@ def test_setitem_numeric_raises(self, arr1d, box): def test_inplace_arithmetic(self): # GH#24115 check that iadd and isub are actually in-place - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") expected = arr + pd.Timedelta(days=1) @@ -553,7 +553,7 @@ def test_inplace_arithmetic(self): def test_shift_fill_int_deprecated(self): # GH#31971 - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") msg = "Passing to shift" diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 73b4e7c19dc2e..ad75c137ec703 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -280,7 +280,7 @@ def test_array_interface(self): @pytest.mark.parametrize("index", [True, False]) def test_searchsorted_different_tz(self, index): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = DatetimeArray(data, freq="D").tz_localize("Asia/Tokyo") if index: arr = pd.Index(arr) @@ -295,7 +295,7 @@ def test_searchsorted_different_tz(self, index): @pytest.mark.parametrize("index", [True, False]) def test_searchsorted_tzawareness_compat(self, index): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = DatetimeArray(data, freq="D") if index: arr = pd.Index(arr) @@ -322,14 +322,14 @@ def test_searchsorted_tzawareness_compat(self, index): np.timedelta64("NaT"), pd.Timedelta(days=2), "invalid", - np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9, - np.arange(10).view("timedelta64[ns]") * 24 * 3600 * 10 ** 9, + np.arange(10, dtype="i8") * 24 * 3600 * 10**9, + np.arange(10).view("timedelta64[ns]") * 24 * 3600 * 10**9, pd.Timestamp("2021-01-01").to_period("D"), ], ) @pytest.mark.parametrize("index", [True, False]) def test_searchsorted_invalid_types(self, other, index): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = DatetimeArray(data, freq="D") if index: arr = pd.Index(arr) diff --git a/pandas/tests/arrays/test_timedeltas.py b/pandas/tests/arrays/test_timedeltas.py index 1db0f6ad56ce3..675c6ac8c9233 100644 --- a/pandas/tests/arrays/test_timedeltas.py +++ b/pandas/tests/arrays/test_timedeltas.py @@ -52,14 +52,14 @@ def test_setitem_objects(self, obj): np.datetime64("NaT"), pd.Timestamp("2021-01-01"), "invalid", - np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9, - (np.arange(10) * 24 * 3600 * 10 ** 9).view("datetime64[ns]"), + np.arange(10, dtype="i8") * 24 * 3600 * 10**9, + (np.arange(10) * 24 * 3600 * 10**9).view("datetime64[ns]"), pd.Timestamp("2021-01-01").to_period("D"), ], ) @pytest.mark.parametrize("index", [True, False]) def test_searchsorted_invalid_types(self, other, index): - data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 + data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = TimedeltaArray(data, freq="D") if index: arr = pd.Index(arr) @@ -76,10 +76,10 @@ def test_searchsorted_invalid_types(self, other, index): class TestUnaryOps: def test_abs(self): - vals = np.array([-3600 * 10 ** 9, "NaT", 7200 * 10 ** 9], dtype="m8[ns]") + vals = np.array([-3600 * 10**9, "NaT", 7200 * 10**9], dtype="m8[ns]") arr = TimedeltaArray(vals) - evals = np.array([3600 * 10 ** 9, "NaT", 7200 * 10 ** 9], dtype="m8[ns]") + evals = np.array([3600 * 10**9, "NaT", 7200 * 10**9], dtype="m8[ns]") expected = TimedeltaArray(evals) result = abs(arr) @@ -89,7 +89,7 @@ def test_abs(self): tm.assert_timedelta_array_equal(result2, expected) def test_pos(self): - vals = np.array([-3600 * 10 ** 9, "NaT", 7200 * 10 ** 9], dtype="m8[ns]") + vals = np.array([-3600 * 10**9, "NaT", 7200 * 10**9], dtype="m8[ns]") arr = TimedeltaArray(vals) result = +arr @@ -101,10 +101,10 @@ def test_pos(self): assert not tm.shares_memory(result2, arr) def test_neg(self): - vals = np.array([-3600 * 10 ** 9, "NaT", 7200 * 10 ** 9], dtype="m8[ns]") + vals = np.array([-3600 * 10**9, "NaT", 7200 * 10**9], dtype="m8[ns]") arr = TimedeltaArray(vals) - evals = np.array([3600 * 10 ** 9, "NaT", -7200 * 10 ** 9], dtype="m8[ns]") + evals = np.array([3600 * 10**9, "NaT", -7200 * 10**9], dtype="m8[ns]") expected = TimedeltaArray(evals) result = -arr diff --git a/pandas/tests/arrays/timedeltas/test_constructors.py b/pandas/tests/arrays/timedeltas/test_constructors.py index d297e745f107b..d24fabfeecb26 100644 --- a/pandas/tests/arrays/timedeltas/test_constructors.py +++ b/pandas/tests/arrays/timedeltas/test_constructors.py @@ -19,7 +19,7 @@ def test_only_1dim_accepted(self): def test_freq_validation(self): # ensure that the public constructor cannot create an invalid instance - arr = np.array([0, 0, 1], dtype=np.int64) * 3600 * 10 ** 9 + arr = np.array([0, 0, 1], dtype=np.int64) * 3600 * 10**9 msg = ( "Inferred frequency None from passed values does not " diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index 84e4992cce0e3..216c9b1546b9d 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -199,7 +199,7 @@ def test_iter_box(self): "datetime64[ns]", ), ( - pd.TimedeltaIndex([10 ** 10]), + pd.TimedeltaIndex([10**10]), TimedeltaArray, "m8[ns]", ), diff --git a/pandas/tests/dtypes/cast/test_can_hold_element.py b/pandas/tests/dtypes/cast/test_can_hold_element.py index 906123b1aee74..06d256c57a631 100644 --- a/pandas/tests/dtypes/cast/test_can_hold_element.py +++ b/pandas/tests/dtypes/cast/test_can_hold_element.py @@ -33,11 +33,11 @@ def test_can_hold_element_range(any_int_numpy_dtype): assert can_hold_element(arr, rng) # empty - rng = range(-(10 ** 10), -(10 ** 10)) + rng = range(-(10**10), -(10**10)) assert len(rng) == 0 # assert can_hold_element(arr, rng) - rng = range(10 ** 10, 10 ** 10) + rng = range(10**10, 10**10) assert len(rng) == 0 assert can_hold_element(arr, rng) @@ -51,7 +51,7 @@ def test_can_hold_element_int_values_float_ndarray(): assert not can_hold_element(arr, element + 0.5) # integer but not losslessly castable to int64 - element = np.array([3, 2 ** 65], dtype=np.float64) + element = np.array([3, 2**65], dtype=np.float64) assert not can_hold_element(arr, element) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 7953d650636be..b4113d877836b 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -594,25 +594,25 @@ def test_convert_non_hashable(self): tm.assert_numpy_array_equal(result, np.array([np.nan, 1.0, np.nan])) def test_convert_numeric_uint64(self): - arr = np.array([2 ** 63], dtype=object) - exp = np.array([2 ** 63], dtype=np.uint64) + arr = np.array([2**63], dtype=object) + exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_numeric(arr, set())[0], exp) - arr = np.array([str(2 ** 63)], dtype=object) - exp = np.array([2 ** 63], dtype=np.uint64) + arr = np.array([str(2**63)], dtype=object) + exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_numeric(arr, set())[0], exp) - arr = np.array([np.uint64(2 ** 63)], dtype=object) - exp = np.array([2 ** 63], dtype=np.uint64) + arr = np.array([np.uint64(2**63)], dtype=object) + exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_numeric(arr, set())[0], exp) @pytest.mark.parametrize( "arr", [ - np.array([2 ** 63, np.nan], dtype=object), - np.array([str(2 ** 63), np.nan], dtype=object), - np.array([np.nan, 2 ** 63], dtype=object), - np.array([np.nan, str(2 ** 63)], dtype=object), + np.array([2**63, np.nan], dtype=object), + np.array([str(2**63), np.nan], dtype=object), + np.array([np.nan, 2**63], dtype=object), + np.array([np.nan, str(2**63)], dtype=object), ], ) def test_convert_numeric_uint64_nan(self, coerce, arr): @@ -624,11 +624,11 @@ def test_convert_numeric_uint64_nan(self, coerce, arr): def test_convert_numeric_uint64_nan_values( self, coerce, convert_to_masked_nullable ): - arr = np.array([2 ** 63, 2 ** 63 + 1], dtype=object) - na_values = {2 ** 63} + arr = np.array([2**63, 2**63 + 1], dtype=object) + na_values = {2**63} expected = ( - np.array([np.nan, 2 ** 63 + 1], dtype=float) if coerce else arr.copy() + np.array([np.nan, 2**63 + 1], dtype=float) if coerce else arr.copy() ) result = lib.maybe_convert_numeric( arr, @@ -638,7 +638,7 @@ def test_convert_numeric_uint64_nan_values( ) if convert_to_masked_nullable and coerce: expected = IntegerArray( - np.array([0, 2 ** 63 + 1], dtype="u8"), + np.array([0, 2**63 + 1], dtype="u8"), np.array([True, False], dtype="bool"), ) result = IntegerArray(*result) @@ -649,12 +649,12 @@ def test_convert_numeric_uint64_nan_values( @pytest.mark.parametrize( "case", [ - np.array([2 ** 63, -1], dtype=object), - np.array([str(2 ** 63), -1], dtype=object), - np.array([str(2 ** 63), str(-1)], dtype=object), - np.array([-1, 2 ** 63], dtype=object), - np.array([-1, str(2 ** 63)], dtype=object), - np.array([str(-1), str(2 ** 63)], dtype=object), + np.array([2**63, -1], dtype=object), + np.array([str(2**63), -1], dtype=object), + np.array([str(2**63), str(-1)], dtype=object), + np.array([-1, 2**63], dtype=object), + np.array([-1, str(2**63)], dtype=object), + np.array([str(-1), str(2**63)], dtype=object), ], ) @pytest.mark.parametrize("convert_to_masked_nullable", [True, False]) @@ -686,7 +686,7 @@ def test_convert_numeric_string_uint64(self, convert_to_masked_nullable): result = result[0] assert np.isnan(result) - @pytest.mark.parametrize("value", [-(2 ** 63) - 1, 2 ** 64]) + @pytest.mark.parametrize("value", [-(2**63) - 1, 2**64]) def test_convert_int_overflow(self, value): # see gh-18584 arr = np.array([value], dtype=object) @@ -695,23 +695,23 @@ def test_convert_int_overflow(self, value): def test_maybe_convert_objects_uint64(self): # see gh-4471 - arr = np.array([2 ** 63], dtype=object) - exp = np.array([2 ** 63], dtype=np.uint64) + arr = np.array([2**63], dtype=object) + exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) # NumPy bug: can't compare uint64 to int64, as that # results in both casting to float64, so we should # make sure that this function is robust against it - arr = np.array([np.uint64(2 ** 63)], dtype=object) - exp = np.array([2 ** 63], dtype=np.uint64) + arr = np.array([np.uint64(2**63)], dtype=object) + exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) arr = np.array([2, -1], dtype=object) exp = np.array([2, -1], dtype=np.int64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) - arr = np.array([2 ** 63, -1], dtype=object) - exp = np.array([2 ** 63, -1], dtype=object) + arr = np.array([2**63, -1], dtype=object) + exp = np.array([2**63, -1], dtype=object) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) def test_maybe_convert_objects_datetime(self): diff --git a/pandas/tests/frame/conftest.py b/pandas/tests/frame/conftest.py index b512664b57ade..8dbed84b85837 100644 --- a/pandas/tests/frame/conftest.py +++ b/pandas/tests/frame/conftest.py @@ -212,7 +212,7 @@ def uint64_frame(): Columns are ['A', 'B'] """ return DataFrame( - {"A": np.arange(3), "B": [2 ** 63, 2 ** 63 + 5, 2 ** 63 + 10]}, dtype=np.uint64 + {"A": np.arange(3), "B": [2**63, 2**63 + 5, 2**63 + 10]}, dtype=np.uint64 ) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 9b6e04dffa6ce..22d8d13b77f72 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -721,7 +721,7 @@ def test_where_datetimelike_noop(self, dtype): # GH#45135, analogue to GH#44181 for Period don't raise on no-op # For td64/dt64/dt64tz we already don't raise, but also are # checking that we don't unnecessarily upcast to object. - ser = Series(np.arange(3) * 10 ** 9, dtype=np.int64).view(dtype) + ser = Series(np.arange(3) * 10**9, dtype=np.int64).view(dtype) df = ser.to_frame() mask = np.array([False, False, False]) @@ -761,9 +761,9 @@ def test_where_int_downcasting_deprecated(using_array_manager): msg = "Downcasting integer-dtype" warn = FutureWarning if not using_array_manager else None with tm.assert_produces_warning(warn, match=msg): - res = df.where(mask, 2 ** 17) + res = df.where(mask, 2**17) - expected = DataFrame({0: arr[:, 0], 1: np.array([2 ** 17] * 3, dtype=np.int32)}) + expected = DataFrame({0: arr[:, 0], 1: np.array([2**17] * 3, dtype=np.int32)}) tm.assert_frame_equal(res, expected) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index d326ca3493977..bc297ebb56b48 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -455,10 +455,10 @@ def test_astype_to_incorrect_datetimelike(self, unit): msg = "|".join( [ # BlockManager path - fr"Cannot cast DatetimeArray to dtype timedelta64\[{unit}\]", + rf"Cannot cast DatetimeArray to dtype timedelta64\[{unit}\]", # ArrayManager path "cannot astype a datetimelike from " - fr"\[datetime64\[ns\]\] to \[timedelta64\[{unit}\]\]", + rf"\[datetime64\[ns\]\] to \[timedelta64\[{unit}\]\]", ] ) with pytest.raises(TypeError, match=msg): @@ -467,10 +467,10 @@ def test_astype_to_incorrect_datetimelike(self, unit): msg = "|".join( [ # BlockManager path - fr"Cannot cast TimedeltaArray to dtype datetime64\[{unit}\]", + rf"Cannot cast TimedeltaArray to dtype datetime64\[{unit}\]", # ArrayManager path "cannot astype a timedelta from " - fr"\[timedelta64\[ns\]\] to \[datetime64\[{unit}\]\]", + rf"\[timedelta64\[ns\]\] to \[datetime64\[{unit}\]\]", ] ) df = DataFrame(np.array([[1, 2, 3]], dtype=other)) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 6a1466ae1ea46..2e545942b6f46 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -348,7 +348,7 @@ def test_corr_numerical_instabilities(self): def test_corrwith_spearman(self): # GH#21925 df = DataFrame(np.random.random(size=(100, 3))) - result = df.corrwith(df ** 2, method="spearman") + result = df.corrwith(df**2, method="spearman") expected = Series(np.ones(len(result))) tm.assert_series_equal(result, expected) @@ -356,6 +356,6 @@ def test_corrwith_spearman(self): def test_corrwith_kendall(self): # GH#21925 df = DataFrame(np.random.random(size=(100, 3))) - result = df.corrwith(df ** 2, method="kendall") + result = df.corrwith(df**2, method="kendall") expected = Series(np.ones(len(result))) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_pipe.py b/pandas/tests/frame/methods/test_pipe.py index 1d7cc16f49280..5bcc4360487f3 100644 --- a/pandas/tests/frame/methods/test_pipe.py +++ b/pandas/tests/frame/methods/test_pipe.py @@ -15,7 +15,7 @@ def test_pipe(self, frame_or_series): obj = obj["A"] expected = expected["A"] - f = lambda x, y: x ** y + f = lambda x, y: x**y result = obj.pipe(f, 2) tm.assert_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index 31a6d7637a244..68c87a59d8230 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -332,7 +332,7 @@ def test_rank_pct_true(self, method, exp): def test_pct_max_many_rows(self): # GH 18271 df = DataFrame( - {"A": np.arange(2 ** 24 + 1), "B": np.arange(2 ** 24 + 1, 0, -1)} + {"A": np.arange(2**24 + 1), "B": np.arange(2**24 + 1, 0, -1)} ) result = df.rank(pct=True).max() assert (result == 1).all() diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index 8130c4fa41c12..8ddda099cf898 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -41,7 +41,7 @@ def test_reset_index_empty_rangeindex(self): def test_set_reset(self): - idx = Index([2 ** 63, 2 ** 63 + 5, 2 ** 63 + 10], name="foo") + idx = Index([2**63, 2**63 + 5, 2**63 + 10], name="foo") # set/reset df = DataFrame({"A": [0, 1, 2]}, index=idx) @@ -232,7 +232,7 @@ def test_reset_index_level(self): def test_reset_index_right_dtype(self): time = np.arange(0.0, 10, np.sqrt(2) / 2) s1 = Series( - (9.81 * time ** 2) / 2, index=Index(time, name="time"), name="speed" + (9.81 * time**2) / 2, index=Index(time, name="time"), name="speed" ) df = DataFrame(s1) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 4820fcce6486b..bde44ddf12a8e 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -870,13 +870,13 @@ def _test_op(df, op): _test_op(df, lambda x, y: y - x) _test_op(df, lambda x, y: y * x) _test_op(df, lambda x, y: y / x) - _test_op(df, lambda x, y: y ** x) + _test_op(df, lambda x, y: y**x) _test_op(df, lambda x, y: x + y) _test_op(df, lambda x, y: x - y) _test_op(df, lambda x, y: x * y) _test_op(df, lambda x, y: x / y) - _test_op(df, lambda x, y: x ** y) + _test_op(df, lambda x, y: x**y) @pytest.mark.parametrize( "values", [[1, 2], (1, 2), np.array([1, 2]), range(1, 3), deque([1, 2])] @@ -949,9 +949,9 @@ def test_frame_with_frame_reindex(self): [ (1, "i8"), (1.0, "f8"), - (2 ** 63, "f8"), + (2**63, "f8"), (1j, "complex128"), - (2 ** 63, "complex128"), + (2**63, "complex128"), (True, "bool"), (np.timedelta64(20, "ns"), " Series diff --git a/pandas/tests/indexes/base_class/test_indexing.py b/pandas/tests/indexes/base_class/test_indexing.py index 9cd582925ff79..8135dd57bba3f 100644 --- a/pandas/tests/indexes/base_class/test_indexing.py +++ b/pandas/tests/indexes/base_class/test_indexing.py @@ -51,7 +51,7 @@ def test_get_loc_tuple_monotonic_above_size_cutoff(self): lev = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") dti = pd.date_range("2016-01-01", periods=100) - mi = pd.MultiIndex.from_product([lev, range(10 ** 3), dti]) + mi = pd.MultiIndex.from_product([lev, range(10**3), dti]) oidx = mi.to_flat_index() loc = len(oidx) // 2 diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 61cfd5593abc0..0cf66c0814293 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -892,6 +892,6 @@ def test_arithmetic_explicit_conversions(self): def test_invalid_dtype(self, invalid_dtype): # GH 29539 dtype = invalid_dtype - msg = fr"Incorrect `dtype` passed: expected \w+(?: \w+)?, received {dtype}" + msg = rf"Incorrect `dtype` passed: expected \w+(?: \w+)?, received {dtype}" with pytest.raises(ValueError, match=msg): self._index_cls([1, 2, 3], dtype=dtype) diff --git a/pandas/tests/indexes/datetimelike_/test_equals.py b/pandas/tests/indexes/datetimelike_/test_equals.py index cc90e8f6d9bec..39e8270b1c4f5 100644 --- a/pandas/tests/indexes/datetimelike_/test_equals.py +++ b/pandas/tests/indexes/datetimelike_/test_equals.py @@ -167,7 +167,7 @@ def test_equals2(self): # Check that we dont raise OverflowError on comparisons outside the # implementation range GH#28532 - oob = Index([timedelta(days=10 ** 6)] * 3, dtype=object) + oob = Index([timedelta(days=10**6)] * 3, dtype=object) assert not idx.equals(oob) assert not idx2.equals(oob) diff --git a/pandas/tests/indexes/datetimelike_/test_indexing.py b/pandas/tests/indexes/datetimelike_/test_indexing.py index eb37c2c4ad2a3..b64d5421a2067 100644 --- a/pandas/tests/indexes/datetimelike_/test_indexing.py +++ b/pandas/tests/indexes/datetimelike_/test_indexing.py @@ -20,7 +20,7 @@ @pytest.mark.parametrize("rdtype", dtlike_dtypes) def test_get_indexer_non_unique_wrong_dtype(ldtype, rdtype): - vals = np.tile(3600 * 10 ** 9 * np.arange(3), 2) + vals = np.tile(3600 * 10**9 * np.arange(3), 2) def construct(dtype): if dtype is dtlike_dtypes[-1]: diff --git a/pandas/tests/indexes/datetimes/test_partial_slicing.py b/pandas/tests/indexes/datetimes/test_partial_slicing.py index 2f32f9e18311d..8ddcd6a453080 100644 --- a/pandas/tests/indexes/datetimes/test_partial_slicing.py +++ b/pandas/tests/indexes/datetimes/test_partial_slicing.py @@ -281,7 +281,7 @@ def test_partial_slicing_dataframe(self): result = df["a"][ts_string] assert isinstance(result, np.int64) assert result == expected - msg = fr"^'{ts_string}'$" + msg = rf"^'{ts_string}'$" with pytest.raises(KeyError, match=msg): df[ts_string] @@ -311,7 +311,7 @@ def test_partial_slicing_dataframe(self): result = df["a"][ts_string] assert isinstance(result, np.int64) assert result == 2 - msg = fr"^'{ts_string}'$" + msg = rf"^'{ts_string}'$" with pytest.raises(KeyError, match=msg): df[ts_string] @@ -320,7 +320,7 @@ def test_partial_slicing_dataframe(self): for fmt, res in list(zip(formats, resolutions))[rnum + 1 :]: ts = index[1] + Timedelta("1 " + res) ts_string = ts.strftime(fmt) - msg = fr"^'{ts_string}'$" + msg = rf"^'{ts_string}'$" with pytest.raises(KeyError, match=msg): df["a"][ts_string] with pytest.raises(KeyError, match=msg): diff --git a/pandas/tests/indexes/interval/test_interval_tree.py b/pandas/tests/indexes/interval/test_interval_tree.py index ab6eac482211d..f2d9ec3608271 100644 --- a/pandas/tests/indexes/interval/test_interval_tree.py +++ b/pandas/tests/indexes/interval/test_interval_tree.py @@ -58,7 +58,7 @@ def test_get_indexer(self, tree): @pytest.mark.parametrize( "dtype, target_value, target_dtype", - [("int64", 2 ** 63 + 1, "uint64"), ("uint64", -1, "int64")], + [("int64", 2**63 + 1, "uint64"), ("uint64", -1, "int64")], ) def test_get_indexer_overflow(self, dtype, target_value, target_dtype): left, right = np.array([0, 1], dtype=dtype), np.array([1, 2], dtype=dtype) @@ -89,7 +89,7 @@ def test_get_indexer_non_unique(self, tree): @pytest.mark.parametrize( "dtype, target_value, target_dtype", - [("int64", 2 ** 63 + 1, "uint64"), ("uint64", -1, "int64")], + [("int64", 2**63 + 1, "uint64"), ("uint64", -1, "int64")], ) def test_get_indexer_non_unique_overflow(self, dtype, target_value, target_dtype): left, right = np.array([0, 2], dtype=dtype), np.array([1, 3], dtype=dtype) diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index 9cb65128e7068..f81d9f9a9ce2a 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -790,8 +790,8 @@ def test_contains_td64_level(self): @pytest.mark.slow def test_large_mi_contains(self): # GH#10645 - result = MultiIndex.from_arrays([range(10 ** 6), range(10 ** 6)]) - assert not (10 ** 6, 0) in result + result = MultiIndex.from_arrays([range(10**6), range(10**6)]) + assert not (10**6, 0) in result def test_timestamp_multiindex_indexer(): diff --git a/pandas/tests/indexes/multi/test_integrity.py b/pandas/tests/indexes/multi/test_integrity.py index e1c2134b5b1f8..b9596ca62d030 100644 --- a/pandas/tests/indexes/multi/test_integrity.py +++ b/pandas/tests/indexes/multi/test_integrity.py @@ -52,7 +52,7 @@ def test_values_boxed(): def test_values_multiindex_datetimeindex(): # Test to ensure we hit the boxing / nobox part of MI.values - ints = np.arange(10 ** 18, 10 ** 18 + 5) + ints = np.arange(10**18, 10**18 + 5) naive = pd.DatetimeIndex(ints) aware = pd.DatetimeIndex(ints, tz="US/Central") diff --git a/pandas/tests/indexes/numeric/test_indexing.py b/pandas/tests/indexes/numeric/test_indexing.py index a70845a4def7f..7081cbdfe6428 100644 --- a/pandas/tests/indexes/numeric/test_indexing.py +++ b/pandas/tests/indexes/numeric/test_indexing.py @@ -20,7 +20,7 @@ @pytest.fixture def index_large(): # large values used in UInt64Index tests where no compat needed with Int64/Float64 - large = [2 ** 63, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20, 2 ** 63 + 25] + large = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25] return UInt64Index(large) @@ -161,7 +161,7 @@ def test_get_loc_float_index_nan_with_method(self, vals, method): @pytest.mark.parametrize("dtype", ["f8", "i8", "u8"]) def test_get_loc_numericindex_none_raises(self, dtype): # case that goes through searchsorted and key is non-comparable to values - arr = np.arange(10 ** 7, dtype=dtype) + arr = np.arange(10**7, dtype=dtype) idx = Index(arr) with pytest.raises(KeyError, match="None"): idx.get_loc(None) @@ -376,17 +376,17 @@ def test_get_indexer_int64(self): tm.assert_numpy_array_equal(indexer, expected) def test_get_indexer_uint64(self, index_large): - target = UInt64Index(np.arange(10).astype("uint64") * 5 + 2 ** 63) + target = UInt64Index(np.arange(10).astype("uint64") * 5 + 2**63) indexer = index_large.get_indexer(target) expected = np.array([0, -1, 1, 2, 3, 4, -1, -1, -1, -1], dtype=np.intp) tm.assert_numpy_array_equal(indexer, expected) - target = UInt64Index(np.arange(10).astype("uint64") * 5 + 2 ** 63) + target = UInt64Index(np.arange(10).astype("uint64") * 5 + 2**63) indexer = index_large.get_indexer(target, method="pad") expected = np.array([0, 0, 1, 2, 3, 4, 4, 4, 4, 4], dtype=np.intp) tm.assert_numpy_array_equal(indexer, expected) - target = UInt64Index(np.arange(10).astype("uint64") * 5 + 2 ** 63) + target = UInt64Index(np.arange(10).astype("uint64") * 5 + 2**63) indexer = index_large.get_indexer(target, method="backfill") expected = np.array([0, 1, 1, 2, 3, 4, -1, -1, -1, -1], dtype=np.intp) tm.assert_numpy_array_equal(indexer, expected) diff --git a/pandas/tests/indexes/numeric/test_join.py b/pandas/tests/indexes/numeric/test_join.py index 2a47289b65aad..9bbe7a64ada87 100644 --- a/pandas/tests/indexes/numeric/test_join.py +++ b/pandas/tests/indexes/numeric/test_join.py @@ -198,13 +198,13 @@ class TestJoinUInt64Index: @pytest.fixture def index_large(self): # large values used in TestUInt64Index where no compat needed with Int64/Float64 - large = [2 ** 63, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20, 2 ** 63 + 25] + large = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25] return UInt64Index(large) def test_join_inner(self, index_large): - other = UInt64Index(2 ** 63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) + other = UInt64Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) other_mono = UInt64Index( - 2 ** 63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") + 2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") ) # not monotonic @@ -216,7 +216,7 @@ def test_join_inner(self, index_large): lidx = lidx.take(ind) ridx = ridx.take(ind) - eres = UInt64Index(2 ** 63 + np.array([10, 25], dtype="uint64")) + eres = UInt64Index(2**63 + np.array([10, 25], dtype="uint64")) elidx = np.array([1, 4], dtype=np.intp) eridx = np.array([5, 2], dtype=np.intp) @@ -242,9 +242,9 @@ def test_join_inner(self, index_large): tm.assert_numpy_array_equal(ridx, eridx) def test_join_left(self, index_large): - other = UInt64Index(2 ** 63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) + other = UInt64Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) other_mono = UInt64Index( - 2 ** 63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") + 2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") ) # not monotonic @@ -267,12 +267,12 @@ def test_join_left(self, index_large): tm.assert_numpy_array_equal(ridx, eridx) # non-unique - idx = UInt64Index(2 ** 63 + np.array([1, 1, 2, 5], dtype="uint64")) - idx2 = UInt64Index(2 ** 63 + np.array([1, 2, 5, 7, 9], dtype="uint64")) + idx = UInt64Index(2**63 + np.array([1, 1, 2, 5], dtype="uint64")) + idx2 = UInt64Index(2**63 + np.array([1, 2, 5, 7, 9], dtype="uint64")) res, lidx, ridx = idx2.join(idx, how="left", return_indexers=True) # 1 is in idx2, so it should be x2 - eres = UInt64Index(2 ** 63 + np.array([1, 1, 2, 5, 7, 9], dtype="uint64")) + eres = UInt64Index(2**63 + np.array([1, 1, 2, 5, 7, 9], dtype="uint64")) eridx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp) elidx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp) @@ -281,9 +281,9 @@ def test_join_left(self, index_large): tm.assert_numpy_array_equal(ridx, eridx) def test_join_right(self, index_large): - other = UInt64Index(2 ** 63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) + other = UInt64Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) other_mono = UInt64Index( - 2 ** 63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") + 2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") ) # not monotonic @@ -309,12 +309,12 @@ def test_join_right(self, index_large): assert ridx is None # non-unique - idx = UInt64Index(2 ** 63 + np.array([1, 1, 2, 5], dtype="uint64")) - idx2 = UInt64Index(2 ** 63 + np.array([1, 2, 5, 7, 9], dtype="uint64")) + idx = UInt64Index(2**63 + np.array([1, 1, 2, 5], dtype="uint64")) + idx2 = UInt64Index(2**63 + np.array([1, 2, 5, 7, 9], dtype="uint64")) res, lidx, ridx = idx.join(idx2, how="right", return_indexers=True) # 1 is in idx2, so it should be x2 - eres = UInt64Index(2 ** 63 + np.array([1, 1, 2, 5, 7, 9], dtype="uint64")) + eres = UInt64Index(2**63 + np.array([1, 1, 2, 5, 7, 9], dtype="uint64")) elidx = np.array([0, 1, 2, 3, -1, -1], dtype=np.intp) eridx = np.array([0, 0, 1, 2, 3, 4], dtype=np.intp) @@ -324,20 +324,20 @@ def test_join_right(self, index_large): def test_join_non_int_index(self, index_large): other = Index( - 2 ** 63 + np.array([1, 5, 7, 10, 20], dtype="uint64"), dtype=object + 2**63 + np.array([1, 5, 7, 10, 20], dtype="uint64"), dtype=object ) outer = index_large.join(other, how="outer") outer2 = other.join(index_large, how="outer") expected = Index( - 2 ** 63 + np.array([0, 1, 5, 7, 10, 15, 20, 25], dtype="uint64") + 2**63 + np.array([0, 1, 5, 7, 10, 15, 20, 25], dtype="uint64") ) tm.assert_index_equal(outer, outer2) tm.assert_index_equal(outer, expected) inner = index_large.join(other, how="inner") inner2 = other.join(index_large, how="inner") - expected = Index(2 ** 63 + np.array([10, 20], dtype="uint64")) + expected = Index(2**63 + np.array([10, 20], dtype="uint64")) tm.assert_index_equal(inner, inner2) tm.assert_index_equal(inner, expected) @@ -354,9 +354,9 @@ def test_join_non_int_index(self, index_large): tm.assert_index_equal(right2, index_large.astype(object)) def test_join_outer(self, index_large): - other = UInt64Index(2 ** 63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) + other = UInt64Index(2**63 + np.array([7, 12, 25, 1, 2, 10], dtype="uint64")) other_mono = UInt64Index( - 2 ** 63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") + 2**63 + np.array([1, 2, 7, 10, 12, 25], dtype="uint64") ) # not monotonic @@ -366,7 +366,7 @@ def test_join_outer(self, index_large): tm.assert_index_equal(res, noidx_res) eres = UInt64Index( - 2 ** 63 + np.array([0, 1, 2, 7, 10, 12, 15, 20, 25], dtype="uint64") + 2**63 + np.array([0, 1, 2, 7, 10, 12, 15, 20, 25], dtype="uint64") ) elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp) eridx = np.array([-1, 3, 4, 0, 5, 1, -1, -1, 2], dtype=np.intp) diff --git a/pandas/tests/indexes/numeric/test_numeric.py b/pandas/tests/indexes/numeric/test_numeric.py index af308379cba5e..85384cbd41ea5 100644 --- a/pandas/tests/indexes/numeric/test_numeric.py +++ b/pandas/tests/indexes/numeric/test_numeric.py @@ -563,8 +563,8 @@ def simple_index(self, dtype): @pytest.fixture( params=[ - [2 ** 63, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20, 2 ** 63 + 25], - [2 ** 63 + 25, 2 ** 63 + 20, 2 ** 63 + 15, 2 ** 63 + 10, 2 ** 63], + [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25], + [2**63 + 25, 2**63 + 20, 2**63 + 15, 2**63 + 10, 2**63], ], ids=["index_inc", "index_dec"], ) @@ -594,21 +594,21 @@ def test_constructor(self, dtype): res = Index([1, 2, 3], dtype=dtype) tm.assert_index_equal(res, idx, exact=exact) - idx = index_cls([1, 2 ** 63]) - res = Index([1, 2 ** 63], dtype=dtype) + idx = index_cls([1, 2**63]) + res = Index([1, 2**63], dtype=dtype) tm.assert_index_equal(res, idx, exact=exact) - idx = index_cls([1, 2 ** 63]) - res = Index([1, 2 ** 63]) + idx = index_cls([1, 2**63]) + res = Index([1, 2**63]) tm.assert_index_equal(res, idx, exact=exact) - idx = Index([-1, 2 ** 63], dtype=object) - res = Index(np.array([-1, 2 ** 63], dtype=object)) + idx = Index([-1, 2**63], dtype=object) + res = Index(np.array([-1, 2**63], dtype=object)) tm.assert_index_equal(res, idx, exact=exact) # https://github.com/pandas-dev/pandas/issues/29526 - idx = index_cls([1, 2 ** 63 + 1], dtype=dtype) - res = Index([1, 2 ** 63 + 1], dtype=dtype) + idx = index_cls([1, 2**63 + 1], dtype=dtype) + res = Index([1, 2**63 + 1], dtype=dtype) tm.assert_index_equal(res, idx, exact=exact) def test_constructor_does_not_cast_to_float(self): diff --git a/pandas/tests/indexes/numeric/test_setops.py b/pandas/tests/indexes/numeric/test_setops.py index 72336d3e33b79..9f2174c2de51e 100644 --- a/pandas/tests/indexes/numeric/test_setops.py +++ b/pandas/tests/indexes/numeric/test_setops.py @@ -19,7 +19,7 @@ @pytest.fixture def index_large(): # large values used in TestUInt64Index where no compat needed with Int64/Float64 - large = [2 ** 63, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20, 2 ** 63 + 25] + large = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25] return UInt64Index(large) @@ -89,7 +89,7 @@ def test_float64_index_difference(self): tm.assert_index_equal(result, string_index) def test_intersection_uint64_outside_int64_range(self, index_large): - other = Index([2 ** 63, 2 ** 63 + 5, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20]) + other = Index([2**63, 2**63 + 5, 2**63 + 10, 2**63 + 15, 2**63 + 20]) result = index_large.intersection(other) expected = Index(np.sort(np.intersect1d(index_large.values, other.values))) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 1145de14ad3c4..222f1fc3e7648 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -743,7 +743,7 @@ def test_drop_tuple(self, values, to_drop): tm.assert_index_equal(result, expected) removed = index.drop(to_drop[1]) - msg = fr"\"\[{re.escape(to_drop[1].__repr__())}\] not found in axis\"" + msg = rf"\"\[{re.escape(to_drop[1].__repr__())}\] not found in axis\"" for drop_me in to_drop[1], [to_drop[1]]: with pytest.raises(KeyError, match=msg): removed.drop(drop_me) @@ -871,7 +871,7 @@ def test_isin_level_kwarg_bad_label_raises(self, label, index): msg = f"'Level {label} not found'" else: index = index.rename("foo") - msg = fr"Requested level \({label}\) does not match index name \(foo\)" + msg = rf"Requested level \({label}\) does not match index name \(foo\)" with pytest.raises(KeyError, match=msg): index.isin([], level=label) diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index 5fb9673cf52d7..6159c53ea5bf4 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -195,8 +195,8 @@ def test_unique_level(self, index_flat): index.unique(level=3) msg = ( - fr"Requested level \(wrong\) does not match index name " - fr"\({re.escape(index.name.__repr__())}\)" + rf"Requested level \(wrong\) does not match index name " + rf"\({re.escape(index.name.__repr__())}\)" ) with pytest.raises(KeyError, match=msg): index.unique(level="wrong") diff --git a/pandas/tests/indexes/timedeltas/test_constructors.py b/pandas/tests/indexes/timedeltas/test_constructors.py index dcddba8b22937..25a0a66ada519 100644 --- a/pandas/tests/indexes/timedeltas/test_constructors.py +++ b/pandas/tests/indexes/timedeltas/test_constructors.py @@ -51,7 +51,7 @@ def test_infer_from_tdi(self): # GH#23539 # fast-path for inferring a frequency if the passed data already # has one - tdi = timedelta_range("1 second", periods=10 ** 7, freq="1s") + tdi = timedelta_range("1 second", periods=10**7, freq="1s") result = TimedeltaIndex(tdi, freq="infer") assert result.freq == tdi.freq diff --git a/pandas/tests/indexes/timedeltas/test_timedelta.py b/pandas/tests/indexes/timedeltas/test_timedelta.py index 8ceef8186e4ea..6904a847b04ed 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta.py @@ -105,7 +105,7 @@ def test_freq_conversion_always_floating(self): tdi = timedelta_range("1 Day", periods=30) res = tdi.astype("m8[s]") - expected = Index((tdi.view("i8") / 10 ** 9).astype(np.float64)) + expected = Index((tdi.view("i8") / 10**9).astype(np.float64)) tm.assert_index_equal(res, expected) # check this matches Series and TimedeltaArray diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 75337cb3f453f..2f616b79a680f 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -114,7 +114,7 @@ def test_setitem_series_int64(self, val, exp_dtype): self._assert_setitem_series_conversion(obj, val, exp, exp_dtype) @pytest.mark.parametrize( - "val,exp_dtype", [(np.int32(1), np.int8), (np.int16(2 ** 9), np.int16)] + "val,exp_dtype", [(np.int32(1), np.int8), (np.int16(2**9), np.int16)] ) def test_setitem_series_int8(self, val, exp_dtype): obj = pd.Series([1, 2, 3, 4], dtype=np.int8) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 902bd943584d9..81e1b82dd432e 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -240,13 +240,13 @@ def test_slice_non_numeric(self, index_func, idx, frame_or_series, indexer_sli): if indexer_sli is tm.iloc: msg = ( "cannot do positional indexing " - fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + rf"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " "type float" ) else: msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers " + rf"on {type(index).__name__} with these indexers " r"\[(3|4)(\.0)?\] " r"of type (float|int)" ) @@ -306,7 +306,7 @@ def test_slice_integer(self): # positional indexing msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers \[-6\.0\] of " + rf"on {type(index).__name__} with these indexers \[-6\.0\] of " "type float" ) with pytest.raises(TypeError, match=msg): @@ -330,7 +330,7 @@ def test_slice_integer(self): # positional indexing msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers \[(2|3)\.5\] of " + rf"on {type(index).__name__} with these indexers \[(2|3)\.5\] of " "type float" ) with pytest.raises(TypeError, match=msg): @@ -350,7 +350,7 @@ def test_integer_positional_indexing(self, idx): klass = RangeIndex msg = ( "cannot do (slice|positional) indexing " - fr"on {klass.__name__} with these indexers \[(2|4)\.0\] of " + rf"on {klass.__name__} with these indexers \[(2|4)\.0\] of " "type float" ) with pytest.raises(TypeError, match=msg): @@ -376,7 +376,7 @@ def test_slice_integer_frame_getitem(self, index_func): # positional indexing msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers \[(0|1)\.0\] of " + rf"on {type(index).__name__} with these indexers \[(0|1)\.0\] of " "type float" ) with pytest.raises(TypeError, match=msg): @@ -391,7 +391,7 @@ def test_slice_integer_frame_getitem(self, index_func): # positional indexing msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers \[-10\.0\] of " + rf"on {type(index).__name__} with these indexers \[-10\.0\] of " "type float" ) with pytest.raises(TypeError, match=msg): @@ -410,7 +410,7 @@ def test_slice_integer_frame_getitem(self, index_func): # positional indexing msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers \[0\.5\] of " + rf"on {type(index).__name__} with these indexers \[0\.5\] of " "type float" ) with pytest.raises(TypeError, match=msg): @@ -434,7 +434,7 @@ def test_float_slice_getitem_with_integer_index_raises(self, idx, index_func): # positional indexing msg = ( "cannot do slice indexing " - fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + rf"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " "type float" ) with pytest.raises(TypeError, match=msg): diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index ee9d276925d41..d5909ce8eb48f 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -747,7 +747,7 @@ def test_iloc_mask(self): # the possibilities locs = np.arange(4) - nums = 2 ** locs + nums = 2**locs reps = [bin(num) for num in nums] df = DataFrame({"locs": locs, "nums": nums}, reps) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 63c5091865160..892de75855c19 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1307,11 +1307,11 @@ def test_loc_getitem_timedelta_0seconds(self): tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( - "val,expected", [(2 ** 63 - 1, Series([1])), (2 ** 63, Series([2]))] + "val,expected", [(2**63 - 1, Series([1])), (2**63, Series([2]))] ) def test_loc_getitem_uint64_scalar(self, val, expected): # see GH#19399 - df = DataFrame([1, 2], index=[2 ** 63 - 1, 2 ** 63]) + df = DataFrame([1, 2], index=[2**63 - 1, 2**63]) result = df.loc[val] expected.name = val @@ -1825,9 +1825,9 @@ class TestLocSetitemWithExpansion: @pytest.mark.slow def test_loc_setitem_with_expansion_large_dataframe(self): # GH#10692 - result = DataFrame({"x": range(10 ** 6)}, dtype="int64") + result = DataFrame({"x": range(10**6)}, dtype="int64") result.loc[len(result)] = len(result) + 1 - expected = DataFrame({"x": range(10 ** 6 + 1)}, dtype="int64") + expected = DataFrame({"x": range(10**6 + 1)}, dtype="int64") tm.assert_frame_equal(result, expected) def test_loc_setitem_empty_series(self): @@ -2735,10 +2735,10 @@ def test_loc_getitem_nullable_index_with_duplicates(): class TestLocSeries: - @pytest.mark.parametrize("val,expected", [(2 ** 63 - 1, 3), (2 ** 63, 4)]) + @pytest.mark.parametrize("val,expected", [(2**63 - 1, 3), (2**63, 4)]) def test_loc_uint64(self, val, expected): # see GH#19399 - ser = Series({2 ** 63 - 1: 3, 2 ** 63: 4}) + ser = Series({2**63 - 1: 3, 2**63: 4}) assert ser.loc[val] == expected def test_loc_getitem(self, string_series, datetime_series): diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 0315783569c23..c69876c6a3956 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -338,8 +338,8 @@ class TestExcelWriter: def test_excel_sheet_size(self, path): # GH 26080 - breaking_row_count = 2 ** 20 + 1 - breaking_col_count = 2 ** 14 + 1 + breaking_row_count = 2**20 + 1 + breaking_col_count = 2**14 + 1 # purposely using two arrays to prevent memory issues while testing row_arr = np.zeros(shape=(breaking_row_count, 1)) col_arr = np.zeros(shape=(1, breaking_col_count)) diff --git a/pandas/tests/io/formats/test_eng_formatting.py b/pandas/tests/io/formats/test_eng_formatting.py index b8e3122cac5c4..2f18623559557 100644 --- a/pandas/tests/io/formats/test_eng_formatting.py +++ b/pandas/tests/io/formats/test_eng_formatting.py @@ -56,57 +56,57 @@ def test_exponents_with_eng_prefix(self): formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True) f = np.sqrt(2) in_out = [ - (f * 10 ** -24, " 1.414y"), - (f * 10 ** -23, " 14.142y"), - (f * 10 ** -22, " 141.421y"), - (f * 10 ** -21, " 1.414z"), - (f * 10 ** -20, " 14.142z"), - (f * 10 ** -19, " 141.421z"), - (f * 10 ** -18, " 1.414a"), - (f * 10 ** -17, " 14.142a"), - (f * 10 ** -16, " 141.421a"), - (f * 10 ** -15, " 1.414f"), - (f * 10 ** -14, " 14.142f"), - (f * 10 ** -13, " 141.421f"), - (f * 10 ** -12, " 1.414p"), - (f * 10 ** -11, " 14.142p"), - (f * 10 ** -10, " 141.421p"), - (f * 10 ** -9, " 1.414n"), - (f * 10 ** -8, " 14.142n"), - (f * 10 ** -7, " 141.421n"), - (f * 10 ** -6, " 1.414u"), - (f * 10 ** -5, " 14.142u"), - (f * 10 ** -4, " 141.421u"), - (f * 10 ** -3, " 1.414m"), - (f * 10 ** -2, " 14.142m"), - (f * 10 ** -1, " 141.421m"), - (f * 10 ** 0, " 1.414"), - (f * 10 ** 1, " 14.142"), - (f * 10 ** 2, " 141.421"), - (f * 10 ** 3, " 1.414k"), - (f * 10 ** 4, " 14.142k"), - (f * 10 ** 5, " 141.421k"), - (f * 10 ** 6, " 1.414M"), - (f * 10 ** 7, " 14.142M"), - (f * 10 ** 8, " 141.421M"), - (f * 10 ** 9, " 1.414G"), - (f * 10 ** 10, " 14.142G"), - (f * 10 ** 11, " 141.421G"), - (f * 10 ** 12, " 1.414T"), - (f * 10 ** 13, " 14.142T"), - (f * 10 ** 14, " 141.421T"), - (f * 10 ** 15, " 1.414P"), - (f * 10 ** 16, " 14.142P"), - (f * 10 ** 17, " 141.421P"), - (f * 10 ** 18, " 1.414E"), - (f * 10 ** 19, " 14.142E"), - (f * 10 ** 20, " 141.421E"), - (f * 10 ** 21, " 1.414Z"), - (f * 10 ** 22, " 14.142Z"), - (f * 10 ** 23, " 141.421Z"), - (f * 10 ** 24, " 1.414Y"), - (f * 10 ** 25, " 14.142Y"), - (f * 10 ** 26, " 141.421Y"), + (f * 10**-24, " 1.414y"), + (f * 10**-23, " 14.142y"), + (f * 10**-22, " 141.421y"), + (f * 10**-21, " 1.414z"), + (f * 10**-20, " 14.142z"), + (f * 10**-19, " 141.421z"), + (f * 10**-18, " 1.414a"), + (f * 10**-17, " 14.142a"), + (f * 10**-16, " 141.421a"), + (f * 10**-15, " 1.414f"), + (f * 10**-14, " 14.142f"), + (f * 10**-13, " 141.421f"), + (f * 10**-12, " 1.414p"), + (f * 10**-11, " 14.142p"), + (f * 10**-10, " 141.421p"), + (f * 10**-9, " 1.414n"), + (f * 10**-8, " 14.142n"), + (f * 10**-7, " 141.421n"), + (f * 10**-6, " 1.414u"), + (f * 10**-5, " 14.142u"), + (f * 10**-4, " 141.421u"), + (f * 10**-3, " 1.414m"), + (f * 10**-2, " 14.142m"), + (f * 10**-1, " 141.421m"), + (f * 10**0, " 1.414"), + (f * 10**1, " 14.142"), + (f * 10**2, " 141.421"), + (f * 10**3, " 1.414k"), + (f * 10**4, " 14.142k"), + (f * 10**5, " 141.421k"), + (f * 10**6, " 1.414M"), + (f * 10**7, " 14.142M"), + (f * 10**8, " 141.421M"), + (f * 10**9, " 1.414G"), + (f * 10**10, " 14.142G"), + (f * 10**11, " 141.421G"), + (f * 10**12, " 1.414T"), + (f * 10**13, " 14.142T"), + (f * 10**14, " 141.421T"), + (f * 10**15, " 1.414P"), + (f * 10**16, " 14.142P"), + (f * 10**17, " 141.421P"), + (f * 10**18, " 1.414E"), + (f * 10**19, " 14.142E"), + (f * 10**20, " 141.421E"), + (f * 10**21, " 1.414Z"), + (f * 10**22, " 14.142Z"), + (f * 10**23, " 141.421Z"), + (f * 10**24, " 1.414Y"), + (f * 10**25, " 14.142Y"), + (f * 10**26, " 141.421Y"), ] self.compare_all(formatter, in_out) @@ -114,57 +114,57 @@ def test_exponents_without_eng_prefix(self): formatter = fmt.EngFormatter(accuracy=4, use_eng_prefix=False) f = np.pi in_out = [ - (f * 10 ** -24, " 3.1416E-24"), - (f * 10 ** -23, " 31.4159E-24"), - (f * 10 ** -22, " 314.1593E-24"), - (f * 10 ** -21, " 3.1416E-21"), - (f * 10 ** -20, " 31.4159E-21"), - (f * 10 ** -19, " 314.1593E-21"), - (f * 10 ** -18, " 3.1416E-18"), - (f * 10 ** -17, " 31.4159E-18"), - (f * 10 ** -16, " 314.1593E-18"), - (f * 10 ** -15, " 3.1416E-15"), - (f * 10 ** -14, " 31.4159E-15"), - (f * 10 ** -13, " 314.1593E-15"), - (f * 10 ** -12, " 3.1416E-12"), - (f * 10 ** -11, " 31.4159E-12"), - (f * 10 ** -10, " 314.1593E-12"), - (f * 10 ** -9, " 3.1416E-09"), - (f * 10 ** -8, " 31.4159E-09"), - (f * 10 ** -7, " 314.1593E-09"), - (f * 10 ** -6, " 3.1416E-06"), - (f * 10 ** -5, " 31.4159E-06"), - (f * 10 ** -4, " 314.1593E-06"), - (f * 10 ** -3, " 3.1416E-03"), - (f * 10 ** -2, " 31.4159E-03"), - (f * 10 ** -1, " 314.1593E-03"), - (f * 10 ** 0, " 3.1416E+00"), - (f * 10 ** 1, " 31.4159E+00"), - (f * 10 ** 2, " 314.1593E+00"), - (f * 10 ** 3, " 3.1416E+03"), - (f * 10 ** 4, " 31.4159E+03"), - (f * 10 ** 5, " 314.1593E+03"), - (f * 10 ** 6, " 3.1416E+06"), - (f * 10 ** 7, " 31.4159E+06"), - (f * 10 ** 8, " 314.1593E+06"), - (f * 10 ** 9, " 3.1416E+09"), - (f * 10 ** 10, " 31.4159E+09"), - (f * 10 ** 11, " 314.1593E+09"), - (f * 10 ** 12, " 3.1416E+12"), - (f * 10 ** 13, " 31.4159E+12"), - (f * 10 ** 14, " 314.1593E+12"), - (f * 10 ** 15, " 3.1416E+15"), - (f * 10 ** 16, " 31.4159E+15"), - (f * 10 ** 17, " 314.1593E+15"), - (f * 10 ** 18, " 3.1416E+18"), - (f * 10 ** 19, " 31.4159E+18"), - (f * 10 ** 20, " 314.1593E+18"), - (f * 10 ** 21, " 3.1416E+21"), - (f * 10 ** 22, " 31.4159E+21"), - (f * 10 ** 23, " 314.1593E+21"), - (f * 10 ** 24, " 3.1416E+24"), - (f * 10 ** 25, " 31.4159E+24"), - (f * 10 ** 26, " 314.1593E+24"), + (f * 10**-24, " 3.1416E-24"), + (f * 10**-23, " 31.4159E-24"), + (f * 10**-22, " 314.1593E-24"), + (f * 10**-21, " 3.1416E-21"), + (f * 10**-20, " 31.4159E-21"), + (f * 10**-19, " 314.1593E-21"), + (f * 10**-18, " 3.1416E-18"), + (f * 10**-17, " 31.4159E-18"), + (f * 10**-16, " 314.1593E-18"), + (f * 10**-15, " 3.1416E-15"), + (f * 10**-14, " 31.4159E-15"), + (f * 10**-13, " 314.1593E-15"), + (f * 10**-12, " 3.1416E-12"), + (f * 10**-11, " 31.4159E-12"), + (f * 10**-10, " 314.1593E-12"), + (f * 10**-9, " 3.1416E-09"), + (f * 10**-8, " 31.4159E-09"), + (f * 10**-7, " 314.1593E-09"), + (f * 10**-6, " 3.1416E-06"), + (f * 10**-5, " 31.4159E-06"), + (f * 10**-4, " 314.1593E-06"), + (f * 10**-3, " 3.1416E-03"), + (f * 10**-2, " 31.4159E-03"), + (f * 10**-1, " 314.1593E-03"), + (f * 10**0, " 3.1416E+00"), + (f * 10**1, " 31.4159E+00"), + (f * 10**2, " 314.1593E+00"), + (f * 10**3, " 3.1416E+03"), + (f * 10**4, " 31.4159E+03"), + (f * 10**5, " 314.1593E+03"), + (f * 10**6, " 3.1416E+06"), + (f * 10**7, " 31.4159E+06"), + (f * 10**8, " 314.1593E+06"), + (f * 10**9, " 3.1416E+09"), + (f * 10**10, " 31.4159E+09"), + (f * 10**11, " 314.1593E+09"), + (f * 10**12, " 3.1416E+12"), + (f * 10**13, " 31.4159E+12"), + (f * 10**14, " 314.1593E+12"), + (f * 10**15, " 3.1416E+15"), + (f * 10**16, " 31.4159E+15"), + (f * 10**17, " 314.1593E+15"), + (f * 10**18, " 3.1416E+18"), + (f * 10**19, " 31.4159E+18"), + (f * 10**20, " 314.1593E+18"), + (f * 10**21, " 3.1416E+21"), + (f * 10**22, " 31.4159E+21"), + (f * 10**23, " 314.1593E+21"), + (f * 10**24, " 3.1416E+24"), + (f * 10**25, " 31.4159E+24"), + (f * 10**26, " 314.1593E+24"), ] self.compare_all(formatter, in_out) diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 01bc94bf594d9..f8015851c9a83 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -282,7 +282,7 @@ def test_to_latex_longtable_without_index(self): ) def test_to_latex_longtable_continued_on_next_page(self, df, expected_number): result = df.to_latex(index=False, longtable=True) - assert fr"\multicolumn{{{expected_number}}}" in result + assert rf"\multicolumn{{{expected_number}}}" in result class TestToLatexHeader: @@ -1006,7 +1006,7 @@ def test_to_latex_na_rep_and_float_format(self, na_rep): ) result = df.to_latex(na_rep=na_rep, float_format="{:.2f}".format) expected = _dedent( - fr""" + rf""" \begin{{tabular}}{{llr}} \toprule {{}} & Group & Data \\ diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index f571daef3b40f..966fddda46bd8 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1275,7 +1275,7 @@ def test_to_json_large_numbers(self, bigNum): expected = '{"0":{"articleId":' + str(bigNum) + "}}" assert json == expected - @pytest.mark.parametrize("bigNum", [-(2 ** 63) - 1, 2 ** 64]) + @pytest.mark.parametrize("bigNum", [-(2**63) - 1, 2**64]) def test_read_json_large_numbers(self, bigNum): # GH20599, 26068 json = StringIO('{"articleId":' + str(bigNum) + "}") diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index b4ae54d48dc68..41a417f6b3ef4 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -428,13 +428,13 @@ def test_datetime_units(self): stamp = Timestamp(val) roundtrip = ujson.decode(ujson.encode(val, date_unit="s")) - assert roundtrip == stamp.value // 10 ** 9 + assert roundtrip == stamp.value // 10**9 roundtrip = ujson.decode(ujson.encode(val, date_unit="ms")) - assert roundtrip == stamp.value // 10 ** 6 + assert roundtrip == stamp.value // 10**6 roundtrip = ujson.decode(ujson.encode(val, date_unit="us")) - assert roundtrip == stamp.value // 10 ** 3 + assert roundtrip == stamp.value // 10**3 roundtrip = ujson.decode(ujson.encode(val, date_unit="ns")) assert roundtrip == stamp.value @@ -606,7 +606,7 @@ def test_encode_long_conversion(self, long_input): assert output == json.dumps(long_input) assert long_input == ujson.decode(output) - @pytest.mark.parametrize("bigNum", [2 ** 64, -(2 ** 63) - 1]) + @pytest.mark.parametrize("bigNum", [2**64, -(2**63) - 1]) def test_dumps_ints_larger_than_maxsize(self, bigNum): encoding = ujson.encode(bigNum) assert str(bigNum) == encoding @@ -628,7 +628,7 @@ def test_loads_non_str_bytes_raises(self): with pytest.raises(TypeError, match=msg): ujson.loads(None) - @pytest.mark.parametrize("val", [3590016419, 2 ** 31, 2 ** 32, (2 ** 32) - 1]) + @pytest.mark.parametrize("val", [3590016419, 2**31, 2**32, (2**32) - 1]) def test_decode_number_with_32bit_sign_bit(self, val): # Test that numbers that fit within 32 bits but would have the # sign bit set (2**31 <= x < 2**32) are decoded properly. diff --git a/pandas/tests/io/parser/common/test_ints.py b/pandas/tests/io/parser/common/test_ints.py index aef2020fe0847..e3159ef3e6a42 100644 --- a/pandas/tests/io/parser/common/test_ints.py +++ b/pandas/tests/io/parser/common/test_ints.py @@ -193,7 +193,7 @@ def test_outside_int64_uint64_range(all_parsers, val): @skip_pyarrow -@pytest.mark.parametrize("exp_data", [[str(-1), str(2 ** 63)], [str(2 ** 63), str(-1)]]) +@pytest.mark.parametrize("exp_data", [[str(-1), str(2**63)], [str(2**63), str(-1)]]) def test_numeric_range_too_wide(all_parsers, exp_data): # No numerical dtype can hold both negative and uint64 # values, so they should be cast as string. diff --git a/pandas/tests/io/parser/test_na_values.py b/pandas/tests/io/parser/test_na_values.py index f9356dfc7d0e3..9fb096bfeb346 100644 --- a/pandas/tests/io/parser/test_na_values.py +++ b/pandas/tests/io/parser/test_na_values.py @@ -469,12 +469,12 @@ def test_na_values_dict_col_index(all_parsers): "data,kwargs,expected", [ ( - str(2 ** 63) + "\n" + str(2 ** 63 + 1), - {"na_values": [2 ** 63]}, - DataFrame([str(2 ** 63), str(2 ** 63 + 1)]), + str(2**63) + "\n" + str(2**63 + 1), + {"na_values": [2**63]}, + DataFrame([str(2**63), str(2**63 + 1)]), ), - (str(2 ** 63) + ",1" + "\n,2", {}, DataFrame([[str(2 ** 63), 1], ["", 2]])), - (str(2 ** 63) + "\n1", {"na_values": [2 ** 63]}, DataFrame([np.nan, 1])), + (str(2**63) + ",1" + "\n,2", {}, DataFrame([[str(2**63), 1], ["", 2]])), + (str(2**63) + "\n1", {"na_values": [2**63]}, DataFrame([np.nan, 1])), ], ) def test_na_values_uint64(all_parsers, data, kwargs, expected): diff --git a/pandas/tests/io/pytables/test_append.py b/pandas/tests/io/pytables/test_append.py index f38ea4d5cf306..ec72ca49747b3 100644 --- a/pandas/tests/io/pytables/test_append.py +++ b/pandas/tests/io/pytables/test_append.py @@ -77,10 +77,10 @@ def test_append(setup_path): np.random.randint(0, high=65535, size=5), dtype=np.uint16 ), "u32": Series( - np.random.randint(0, high=2 ** 30, size=5), dtype=np.uint32 + np.random.randint(0, high=2**30, size=5), dtype=np.uint32 ), "u64": Series( - [2 ** 58, 2 ** 59, 2 ** 60, 2 ** 61, 2 ** 62], + [2**58, 2**59, 2**60, 2**61, 2**62], dtype=np.uint64, ), }, diff --git a/pandas/tests/io/pytables/test_compat.py b/pandas/tests/io/pytables/test_compat.py index c7200385aa998..5fe55fda8a452 100644 --- a/pandas/tests/io/pytables/test_compat.py +++ b/pandas/tests/io/pytables/test_compat.py @@ -23,7 +23,7 @@ def pytables_hdf5_file(): testsamples = [ {"c0": t0, "c1": "aaaaa", "c2": 1}, {"c0": t0 + 1, "c1": "bbbbb", "c2": 2}, - {"c0": t0 + 2, "c1": "ccccc", "c2": 10 ** 5}, + {"c0": t0 + 2, "c1": "ccccc", "c2": 10**5}, {"c0": t0 + 3, "c1": "ddddd", "c2": 4_294_967_295}, ] diff --git a/pandas/tests/io/test_common.py b/pandas/tests/io/test_common.py index b458f3351c860..36048601b3248 100644 --- a/pandas/tests/io/test_common.py +++ b/pandas/tests/io/test_common.py @@ -195,23 +195,23 @@ def test_read_non_existent(self, reader, module, error_class, fn_ext): pytest.importorskip(module) path = os.path.join(HERE, "data", "does_not_exist." + fn_ext) - msg1 = fr"File (b')?.+does_not_exist\.{fn_ext}'? does not exist" - msg2 = fr"\[Errno 2\] No such file or directory: '.+does_not_exist\.{fn_ext}'" + msg1 = rf"File (b')?.+does_not_exist\.{fn_ext}'? does not exist" + msg2 = rf"\[Errno 2\] No such file or directory: '.+does_not_exist\.{fn_ext}'" msg3 = "Expected object or value" msg4 = "path_or_buf needs to be a string file path or file-like" msg5 = ( - fr"\[Errno 2\] File .+does_not_exist\.{fn_ext} does not exist: " - fr"'.+does_not_exist\.{fn_ext}'" + rf"\[Errno 2\] File .+does_not_exist\.{fn_ext} does not exist: " + rf"'.+does_not_exist\.{fn_ext}'" ) - msg6 = fr"\[Errno 2\] 没有那个文件或目录: '.+does_not_exist\.{fn_ext}'" + msg6 = rf"\[Errno 2\] 没有那个文件或目录: '.+does_not_exist\.{fn_ext}'" msg7 = ( - fr"\[Errno 2\] File o directory non esistente: '.+does_not_exist\.{fn_ext}'" + rf"\[Errno 2\] File o directory non esistente: '.+does_not_exist\.{fn_ext}'" ) - msg8 = fr"Failed to open local file.+does_not_exist\.{fn_ext}" + msg8 = rf"Failed to open local file.+does_not_exist\.{fn_ext}" with pytest.raises( error_class, - match=fr"({msg1}|{msg2}|{msg3}|{msg4}|{msg5}|{msg6}|{msg7}|{msg8})", + match=rf"({msg1}|{msg2}|{msg3}|{msg4}|{msg5}|{msg6}|{msg7}|{msg8})", ): reader(path) @@ -265,23 +265,23 @@ def test_read_expands_user_home_dir( path = os.path.join("~", "does_not_exist." + fn_ext) monkeypatch.setattr(icom, "_expand_user", lambda x: os.path.join("foo", x)) - msg1 = fr"File (b')?.+does_not_exist\.{fn_ext}'? does not exist" - msg2 = fr"\[Errno 2\] No such file or directory: '.+does_not_exist\.{fn_ext}'" + msg1 = rf"File (b')?.+does_not_exist\.{fn_ext}'? does not exist" + msg2 = rf"\[Errno 2\] No such file or directory: '.+does_not_exist\.{fn_ext}'" msg3 = "Unexpected character found when decoding 'false'" msg4 = "path_or_buf needs to be a string file path or file-like" msg5 = ( - fr"\[Errno 2\] File .+does_not_exist\.{fn_ext} does not exist: " - fr"'.+does_not_exist\.{fn_ext}'" + rf"\[Errno 2\] File .+does_not_exist\.{fn_ext} does not exist: " + rf"'.+does_not_exist\.{fn_ext}'" ) - msg6 = fr"\[Errno 2\] 没有那个文件或目录: '.+does_not_exist\.{fn_ext}'" + msg6 = rf"\[Errno 2\] 没有那个文件或目录: '.+does_not_exist\.{fn_ext}'" msg7 = ( - fr"\[Errno 2\] File o directory non esistente: '.+does_not_exist\.{fn_ext}'" + rf"\[Errno 2\] File o directory non esistente: '.+does_not_exist\.{fn_ext}'" ) - msg8 = fr"Failed to open local file.+does_not_exist\.{fn_ext}" + msg8 = rf"Failed to open local file.+does_not_exist\.{fn_ext}" with pytest.raises( error_class, - match=fr"({msg1}|{msg2}|{msg3}|{msg4}|{msg5}|{msg6}|{msg7}|{msg8})", + match=rf"({msg1}|{msg2}|{msg3}|{msg4}|{msg5}|{msg6}|{msg7}|{msg8})", ): reader(path) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 8263c437030eb..4d483099157ae 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -369,7 +369,7 @@ def test_frame1(): def test_frame3(): columns = ["index", "A", "B"] data = [ - ("2000-01-03 00:00:00", 2 ** 31 - 1, -1.987670), + ("2000-01-03 00:00:00", 2**31 - 1, -1.987670), ("2000-01-04 00:00:00", -29, -0.0412318367011), ("2000-01-05 00:00:00", 20000, 0.731167677815), ("2000-01-06 00:00:00", -290867, 1.56762092543), @@ -1721,7 +1721,7 @@ def test_default_type_conversion(self): def test_bigint(self): # int64 should be converted to BigInteger, GH7433 - df = DataFrame(data={"i64": [2 ** 62]}) + df = DataFrame(data={"i64": [2**62]}) assert df.to_sql("test_bigint", self.conn, index=False) == 1 result = sql.read_sql_table("test_bigint", self.conn) @@ -1963,7 +1963,7 @@ def test_datetime_time(self): def test_mixed_dtype_insert(self): # see GH6509 - s1 = Series(2 ** 25 + 1, dtype=np.int32) + s1 = Series(2**25 + 1, dtype=np.int32) s2 = Series(0.0, dtype=np.float32) df = DataFrame({"s1": s1, "s2": s2}) diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index f0fd391c2a9c4..235b285551ecc 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -477,9 +477,9 @@ def test_read_write_dta12(self, version): tm.assert_frame_equal(written_and_read_again.set_index("index"), formatted) def test_read_write_dta13(self): - s1 = Series(2 ** 9, dtype=np.int16) - s2 = Series(2 ** 17, dtype=np.int32) - s3 = Series(2 ** 33, dtype=np.int64) + s1 = Series(2**9, dtype=np.int16) + s2 = Series(2**17, dtype=np.int32) + s3 = Series(2**33, dtype=np.int64) original = DataFrame({"int16": s1, "int32": s2, "int64": s3}) original.index.name = "index" @@ -610,8 +610,8 @@ def test_string_no_dates(self): def test_large_value_conversion(self): s0 = Series([1, 99], dtype=np.int8) s1 = Series([1, 127], dtype=np.int8) - s2 = Series([1, 2 ** 15 - 1], dtype=np.int16) - s3 = Series([1, 2 ** 63 - 1], dtype=np.int64) + s2 = Series([1, 2**15 - 1], dtype=np.int16) + s3 = Series([1, 2**63 - 1], dtype=np.int64) original = DataFrame({"s0": s0, "s1": s1, "s2": s2, "s3": s3}) original.index.name = "index" with tm.ensure_clean() as path: @@ -699,10 +699,10 @@ def test_bool_uint(self, byteorder, version): s0 = Series([0, 1, True], dtype=np.bool_) s1 = Series([0, 1, 100], dtype=np.uint8) s2 = Series([0, 1, 255], dtype=np.uint8) - s3 = Series([0, 1, 2 ** 15 - 100], dtype=np.uint16) - s4 = Series([0, 1, 2 ** 16 - 1], dtype=np.uint16) - s5 = Series([0, 1, 2 ** 31 - 100], dtype=np.uint32) - s6 = Series([0, 1, 2 ** 32 - 1], dtype=np.uint32) + s3 = Series([0, 1, 2**15 - 100], dtype=np.uint16) + s4 = Series([0, 1, 2**16 - 1], dtype=np.uint16) + s5 = Series([0, 1, 2**31 - 100], dtype=np.uint32) + s6 = Series([0, 1, 2**32 - 1], dtype=np.uint32) original = DataFrame( {"s0": s0, "s1": s1, "s2": s2, "s3": s3, "s4": s4, "s5": s5, "s6": s6} @@ -1999,7 +1999,7 @@ def test_iterator_value_labels(): def test_precision_loss(): df = DataFrame( - [[sum(2 ** i for i in range(60)), sum(2 ** i for i in range(52))]], + [[sum(2**i for i in range(60)), sum(2**i for i in range(52))]], columns=["big", "little"], ) with tm.ensure_clean() as path: diff --git a/pandas/tests/plotting/test_converter.py b/pandas/tests/plotting/test_converter.py index d595f4b453b28..8243b6b73f8d8 100644 --- a/pandas/tests/plotting/test_converter.py +++ b/pandas/tests/plotting/test_converter.py @@ -213,7 +213,7 @@ def test_conversion(self): assert rs[1] == xp def test_conversion_float(self): - rtol = 0.5 * 10 ** -9 + rtol = 0.5 * 10**-9 rs = self.dtc.convert(Timestamp("2012-1-1 01:02:03", tz="UTC"), None, None) xp = converter.dates.date2num(Timestamp("2012-1-1 01:02:03", tz="UTC")) @@ -261,7 +261,7 @@ def test_time_formatter(self, time, format_expected): assert result == format_expected def test_dateindex_conversion(self): - rtol = 10 ** -9 + rtol = 10**-9 for freq in ("B", "L", "S"): dateindex = tm.makeDateIndex(k=10, freq=freq) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 70e739d1440d6..445f3aa7defec 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -210,8 +210,8 @@ class TestIndexReductions: [ (0, 400, 3), (500, 0, -6), - (-(10 ** 6), 10 ** 6, 4), - (10 ** 6, -(10 ** 6), -4), + (-(10**6), 10**6, 4), + (10**6, -(10**6), -4), (0, 10, 20), ], ) @@ -1451,16 +1451,16 @@ def test_mode_category(self, dropna, expected1, expected2, expected3): @pytest.mark.parametrize( "dropna, expected1, expected2", - [(True, [2 ** 63], [1, 2 ** 63]), (False, [2 ** 63], [1, 2 ** 63])], + [(True, [2**63], [1, 2**63]), (False, [2**63], [1, 2**63])], ) def test_mode_intoverflow(self, dropna, expected1, expected2): # Test for uint64 overflow. - s = Series([1, 2 ** 63, 2 ** 63], dtype=np.uint64) + s = Series([1, 2**63, 2**63], dtype=np.uint64) result = s.mode(dropna) expected1 = Series(expected1, dtype=np.uint64) tm.assert_series_equal(result, expected1) - s = Series([1, 2 ** 63], dtype=np.uint64) + s = Series([1, 2**63], dtype=np.uint64) result = s.mode(dropna) expected2 = Series(expected2, dtype=np.uint64) tm.assert_series_equal(result, expected2) diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 2f1ae5df0d5d4..0a6c0ccc891bb 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -128,7 +128,7 @@ def _check_stat_op( # GH#2888 items = [0] - items.extend(range(2 ** 40, 2 ** 40 + 1000)) + items.extend(range(2**40, 2**40 + 1000)) s = Series(items, dtype="int64") tm.assert_almost_equal(float(f(s)), float(alternate(s.values))) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index a023adfb509a0..3caa54e11f8ed 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2004,7 +2004,7 @@ def __init__(self, *args, **kwargs): with monkeypatch.context() as m: m.setattr(reshape_lib, "_Unstacker", MockUnstacker) df = DataFrame( - {"ind1": np.arange(2 ** 16), "ind2": np.arange(2 ** 16), "count": 0} + {"ind1": np.arange(2**16), "ind2": np.arange(2**16), "count": 0} ) msg = "The following operation may generate" diff --git a/pandas/tests/scalar/test_na_scalar.py b/pandas/tests/scalar/test_na_scalar.py index 77265e8745315..88b06ec578905 100644 --- a/pandas/tests/scalar/test_na_scalar.py +++ b/pandas/tests/scalar/test_na_scalar.py @@ -100,7 +100,7 @@ def test_comparison_ops(): def test_pow_special(value, asarray): if asarray: value = np.array([value]) - result = NA ** value + result = NA**value if asarray: result = result[0] @@ -117,7 +117,7 @@ def test_pow_special(value, asarray): def test_rpow_special(value, asarray): if asarray: value = np.array([value]) - result = value ** NA + result = value**NA if asarray: result = result[0] @@ -133,7 +133,7 @@ def test_rpow_special(value, asarray): def test_rpow_minus_one(value, asarray): if asarray: value = np.array([value]) - result = value ** NA + result = value**NA if asarray: result = result[0] diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 36ad24f2e1ef2..ff1f6ad42feb3 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -427,9 +427,9 @@ def test_td_div_td64_non_nano(self): # truediv td = Timedelta("1 days 2 hours 3 ns") result = td / np.timedelta64(1, "D") - assert result == td.value / (86400 * 10 ** 9) + assert result == td.value / (86400 * 10**9) result = td / np.timedelta64(1, "s") - assert result == td.value / 10 ** 9 + assert result == td.value / 10**9 result = td / np.timedelta64(1, "ns") assert result == td.value @@ -694,7 +694,7 @@ def test_td_rfloordiv_timedeltalike_array(self): def test_td_rfloordiv_intarray(self): # deprecated GH#19761, enforced GH#29797 - ints = np.array([1349654400, 1349740800, 1349827200, 1349913600]) * 10 ** 9 + ints = np.array([1349654400, 1349740800, 1349827200, 1349913600]) * 10**9 msg = "Invalid dtype" with pytest.raises(TypeError, match=msg): diff --git a/pandas/tests/scalar/timestamp/test_arithmetic.py b/pandas/tests/scalar/timestamp/test_arithmetic.py index 2ff1de51c33ad..b46962fb82896 100644 --- a/pandas/tests/scalar/timestamp/test_arithmetic.py +++ b/pandas/tests/scalar/timestamp/test_arithmetic.py @@ -61,7 +61,7 @@ def test_overflow_offset_raises(self): # used to crash, so check for proper overflow exception stamp = Timestamp("2000/1/1") - offset_overflow = to_offset("D") * 100 ** 5 + offset_overflow = to_offset("D") * 100**5 with pytest.raises(OverflowError, match=lmsg): stamp + offset_overflow diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index b3deb1a57e5c3..25f3f9c98023b 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -292,20 +292,17 @@ def test_constructor_keyword(self): Timestamp("20151112") ) - assert ( - repr( - Timestamp( - year=2015, - month=11, - day=12, - hour=1, - minute=2, - second=3, - microsecond=999999, - ) + assert repr( + Timestamp( + year=2015, + month=11, + day=12, + hour=1, + minute=2, + second=3, + microsecond=999999, ) - == repr(Timestamp("2015-11-12 01:02:03.999999")) - ) + ) == repr(Timestamp("2015-11-12 01:02:03.999999")) @pytest.mark.filterwarnings("ignore:Timestamp.freq is:FutureWarning") @pytest.mark.filterwarnings("ignore:The 'freq' argument:FutureWarning") diff --git a/pandas/tests/series/indexing/test_setitem.py b/pandas/tests/series/indexing/test_setitem.py index fb07b28c5a54f..c3f82ff3d8285 100644 --- a/pandas/tests/series/indexing/test_setitem.py +++ b/pandas/tests/series/indexing/test_setitem.py @@ -1058,7 +1058,7 @@ def inplace(self): [ np.array([2.0, 3.0]), np.array([2.5, 3.5]), - np.array([2 ** 65, 2 ** 65 + 1], dtype=np.float64), # all ints, but can't cast + np.array([2**65, 2**65 + 1], dtype=np.float64), # all ints, but can't cast ], ) class TestSetitemFloatNDarrayIntoIntegerSeries(SetitemCastingEquivalents): @@ -1117,7 +1117,7 @@ def test_mask_key(self, obj, key, expected, val, indexer_sli, request): super().test_mask_key(obj, key, expected, val, indexer_sli) -@pytest.mark.parametrize("val", [2 ** 33 + 1.0, 2 ** 33 + 1.1, 2 ** 62]) +@pytest.mark.parametrize("val", [2**33 + 1.0, 2**33 + 1.1, 2**62]) class TestSmallIntegerSetitemUpcast(SetitemCastingEquivalents): # https://github.com/pandas-dev/pandas/issues/39584#issuecomment-941212124 @pytest.fixture @@ -1134,9 +1134,9 @@ def inplace(self): @pytest.fixture def expected(self, val): - if val == 2 ** 62: + if val == 2**62: return Series([val, 2, 3], dtype="i8") - elif val == 2 ** 33 + 1.1: + elif val == 2**33 + 1.1: return Series([val, 2, 3], dtype="f8") else: return Series([val, 2, 3], dtype="i8") diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index 8197722687e78..01140f29aa5d9 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -135,8 +135,8 @@ def test_astype_generic_timestamp_no_frequency(self, dtype, request): request.node.add_marker(mark) msg = ( - fr"The '{dtype.__name__}' dtype has no unit\. " - fr"Please pass in '{dtype.__name__}\[ns\]' instead." + rf"The '{dtype.__name__}' dtype has no unit\. " + rf"Please pass in '{dtype.__name__}\[ns\]' instead." ) with pytest.raises(ValueError, match=msg): ser.astype(dtype) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 9617565cab0b4..d3667c9343f53 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -277,7 +277,7 @@ def test_timedelta_fillna(self, frame_or_series): expected = frame_or_series(expected) tm.assert_equal(result, expected) - result = obj.fillna(np.timedelta64(10 ** 9)) + result = obj.fillna(np.timedelta64(10**9)) expected = Series( [ timedelta(seconds=1), diff --git a/pandas/tests/series/methods/test_isin.py b/pandas/tests/series/methods/test_isin.py index f769c08a512ef..2288dfb5c2409 100644 --- a/pandas/tests/series/methods/test_isin.py +++ b/pandas/tests/series/methods/test_isin.py @@ -22,7 +22,7 @@ def test_isin(self): # This specific issue has to have a series over 1e6 in len, but the # comparison array (in_list) must be large enough so that numpy doesn't # do a manual masking trick that will avoid this issue altogether - s = Series(list("abcdefghijk" * 10 ** 5)) + s = Series(list("abcdefghijk" * 10**5)) # If numpy doesn't do the manual comparison/mask, these # unorderable mixed types are what cause the exception in numpy in_list = [-1, "a", "b", "G", "Y", "Z", "E", "K", "E", "S", "I", "R", "R"] * 6 diff --git a/pandas/tests/series/methods/test_rank.py b/pandas/tests/series/methods/test_rank.py index b49ffda4a7a91..4ab99673dfe46 100644 --- a/pandas/tests/series/methods/test_rank.py +++ b/pandas/tests/series/methods/test_rank.py @@ -479,6 +479,6 @@ def test_rank_first_pct(dtype, ser, exp): @pytest.mark.high_memory def test_pct_max_many_rows(): # GH 18271 - s = Series(np.arange(2 ** 24 + 1)) + s = Series(np.arange(2**24 + 1)) result = s.rank(pct=True).max() assert result == 1 diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index cab5fd456d69f..293ae86a3965f 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1585,28 +1585,28 @@ def test_constructor_range_dtype(self, dtype): def test_constructor_range_overflows(self): # GH#30173 range objects that overflow int64 - rng = range(2 ** 63, 2 ** 63 + 4) + rng = range(2**63, 2**63 + 4) ser = Series(rng) expected = Series(list(rng)) tm.assert_series_equal(ser, expected) assert list(ser) == list(rng) assert ser.dtype == np.uint64 - rng2 = range(2 ** 63 + 4, 2 ** 63, -1) + rng2 = range(2**63 + 4, 2**63, -1) ser2 = Series(rng2) expected2 = Series(list(rng2)) tm.assert_series_equal(ser2, expected2) assert list(ser2) == list(rng2) assert ser2.dtype == np.uint64 - rng3 = range(-(2 ** 63), -(2 ** 63) - 4, -1) + rng3 = range(-(2**63), -(2**63) - 4, -1) ser3 = Series(rng3) expected3 = Series(list(rng3)) tm.assert_series_equal(ser3, expected3) assert list(ser3) == list(rng3) assert ser3.dtype == object - rng4 = range(2 ** 73, 2 ** 73 + 4) + rng4 = range(2**73, 2**73 + 4) ser4 = Series(rng4) expected4 = Series(list(rng4)) tm.assert_series_equal(ser4, expected4) diff --git a/pandas/tests/series/test_reductions.py b/pandas/tests/series/test_reductions.py index 8fb51af70f3a0..d2a3de7577353 100644 --- a/pandas/tests/series/test_reductions.py +++ b/pandas/tests/series/test_reductions.py @@ -94,7 +94,7 @@ def test_validate_any_all_out_keepdims_raises(kwargs, func): msg = ( f"the '{param}' parameter is not " "supported in the pandas " - fr"implementation of {name}\(\)" + rf"implementation of {name}\(\)" ) with pytest.raises(ValueError, match=msg): func(ser, **kwargs) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 0007a966840e8..5cae600bbd8b8 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -266,20 +266,20 @@ def test_float64_factorize(self, writable): tm.assert_numpy_array_equal(uniques, expected_uniques) def test_uint64_factorize(self, writable): - data = np.array([2 ** 64 - 1, 1, 2 ** 64 - 1], dtype=np.uint64) + data = np.array([2**64 - 1, 1, 2**64 - 1], dtype=np.uint64) data.setflags(write=writable) expected_codes = np.array([0, 1, 0], dtype=np.intp) - expected_uniques = np.array([2 ** 64 - 1, 1], dtype=np.uint64) + expected_uniques = np.array([2**64 - 1, 1], dtype=np.uint64) codes, uniques = algos.factorize(data) tm.assert_numpy_array_equal(codes, expected_codes) tm.assert_numpy_array_equal(uniques, expected_uniques) def test_int64_factorize(self, writable): - data = np.array([2 ** 63 - 1, -(2 ** 63), 2 ** 63 - 1], dtype=np.int64) + data = np.array([2**63 - 1, -(2**63), 2**63 - 1], dtype=np.int64) data.setflags(write=writable) expected_codes = np.array([0, 1, 0], dtype=np.intp) - expected_uniques = np.array([2 ** 63 - 1, -(2 ** 63)], dtype=np.int64) + expected_uniques = np.array([2**63 - 1, -(2**63)], dtype=np.int64) codes, uniques = algos.factorize(data) tm.assert_numpy_array_equal(codes, expected_codes) @@ -354,7 +354,7 @@ def test_factorize_rangeindex_decreasing(self, sort): def test_deprecate_order(self): # gh 19727 - check warning is raised for deprecated keyword, order. # Test not valid once order keyword is removed. - data = np.array([2 ** 63, 1, 2 ** 63], dtype=np.uint64) + data = np.array([2**63, 1, 2**63], dtype=np.uint64) with pytest.raises(TypeError, match="got an unexpected keyword"): algos.factorize(data, order=True) with tm.assert_produces_warning(False): @@ -364,7 +364,7 @@ def test_deprecate_order(self): "data", [ np.array([0, 1, 0], dtype="u8"), - np.array([-(2 ** 63), 1, -(2 ** 63)], dtype="i8"), + np.array([-(2**63), 1, -(2**63)], dtype="i8"), np.array(["__nan__", "foo", "__nan__"], dtype="object"), ], ) @@ -381,8 +381,8 @@ def test_parametrized_factorize_na_value_default(self, data): [ (np.array([0, 1, 0, 2], dtype="u8"), 0), (np.array([1, 0, 1, 2], dtype="u8"), 1), - (np.array([-(2 ** 63), 1, -(2 ** 63), 0], dtype="i8"), -(2 ** 63)), - (np.array([1, -(2 ** 63), 1, 0], dtype="i8"), 1), + (np.array([-(2**63), 1, -(2**63), 0], dtype="i8"), -(2**63)), + (np.array([1, -(2**63), 1, 0], dtype="i8"), 1), (np.array(["a", "", "a", "b"], dtype=object), "a"), (np.array([(), ("a", 1), (), ("a", 2)], dtype=object), ()), (np.array([("a", 1), (), ("a", 1), ("a", 2)], dtype=object), ("a", 1)), @@ -601,8 +601,8 @@ def test_timedelta64_dtype_array_returned(self): assert result.dtype == expected.dtype def test_uint64_overflow(self): - s = Series([1, 2, 2 ** 63, 2 ** 63], dtype=np.uint64) - exp = np.array([1, 2, 2 ** 63], dtype=np.uint64) + s = Series([1, 2, 2**63, 2**63], dtype=np.uint64) + exp = np.array([1, 2, 2**63], dtype=np.uint64) tm.assert_numpy_array_equal(algos.unique(s), exp) def test_nan_in_object_array(self): @@ -1280,14 +1280,14 @@ def test_value_counts_normalized(self, dtype): tm.assert_series_equal(result, expected) def test_value_counts_uint64(self): - arr = np.array([2 ** 63], dtype=np.uint64) - expected = Series([1], index=[2 ** 63]) + arr = np.array([2**63], dtype=np.uint64) + expected = Series([1], index=[2**63]) result = algos.value_counts(arr) tm.assert_series_equal(result, expected) - arr = np.array([-1, 2 ** 63], dtype=object) - expected = Series([1, 1], index=[-1, 2 ** 63]) + arr = np.array([-1, 2**63], dtype=object) + expected = Series([1, 1], index=[-1, 2**63]) result = algos.value_counts(arr) tm.assert_series_equal(result, expected) @@ -1354,7 +1354,7 @@ def test_duplicated_with_nas(self): ), np.array(["a", "b", "a", "e", "c", "b", "d", "a", "e", "f"], dtype=object), np.array( - [1, 2 ** 63, 1, 3 ** 5, 10, 2 ** 63, 39, 1, 3 ** 5, 7], dtype=np.uint64 + [1, 2**63, 1, 3**5, 10, 2**63, 39, 1, 3**5, 7], dtype=np.uint64 ), ], ) @@ -1572,7 +1572,7 @@ def test_add_different_nans(self): assert len(m) == 1 # NAN1 and NAN2 are equivalent def test_lookup_overflow(self, writable): - xs = np.array([1, 2, 2 ** 63], dtype=np.uint64) + xs = np.array([1, 2, 2**63], dtype=np.uint64) # GH 21688 ensure we can deal with readonly memory views xs.setflags(write=writable) m = ht.UInt64HashTable() @@ -1580,8 +1580,8 @@ def test_lookup_overflow(self, writable): tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=np.intp)) def test_get_unique(self): - s = Series([1, 2, 2 ** 63, 2 ** 63], dtype=np.uint64) - exp = np.array([1, 2, 2 ** 63], dtype=np.uint64) + s = Series([1, 2, 2**63, 2**63], dtype=np.uint64) + exp = np.array([1, 2, 2**63], dtype=np.uint64) tm.assert_numpy_array_equal(s.unique(), exp) @pytest.mark.parametrize("nvals", [0, 10]) # resizing to 0 is special case @@ -1777,7 +1777,7 @@ def test_basic(self, writable, dtype): def test_uint64_overflow(self, dtype): exp = np.array([1, 2], dtype=np.float64) - s = Series([1, 2 ** 63], dtype=dtype) + s = Series([1, 2**63], dtype=dtype) tm.assert_numpy_array_equal(algos.rank(s), exp) def test_too_many_ndims(self): @@ -1791,11 +1791,11 @@ def test_too_many_ndims(self): @pytest.mark.high_memory def test_pct_max_many_rows(self): # GH 18271 - values = np.arange(2 ** 24 + 1) + values = np.arange(2**24 + 1) result = algos.rank(values, pct=True).max() assert result == 1 - values = np.arange(2 ** 25 + 2).reshape(2 ** 24 + 1, 2) + values = np.arange(2**25 + 2).reshape(2**24 + 1, 2) result = algos.rank(values, pct=True).max() assert result == 1 @@ -2361,13 +2361,13 @@ def test_mixed_dtype(self): tm.assert_series_equal(ser.mode(), exp) def test_uint64_overflow(self): - exp = Series([2 ** 63], dtype=np.uint64) - ser = Series([1, 2 ** 63, 2 ** 63], dtype=np.uint64) + exp = Series([2**63], dtype=np.uint64) + ser = Series([1, 2**63, 2**63], dtype=np.uint64) tm.assert_numpy_array_equal(algos.mode(ser.values), exp.values) tm.assert_series_equal(ser.mode(), exp) - exp = Series([1, 2 ** 63], dtype=np.uint64) - ser = Series([1, 2 ** 63], dtype=np.uint64) + exp = Series([1, 2**63], dtype=np.uint64) + ser = Series([1, 2**63], dtype=np.uint64) tm.assert_numpy_array_equal(algos.mode(ser.values), exp.values) tm.assert_series_equal(ser.mode(), exp) diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 0850ba66bbdbd..cbd11cd6d8685 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -64,7 +64,7 @@ def test_random_state(): # check array-like # GH32503 - state_arr_like = npr.randint(0, 2 ** 31, size=624, dtype="uint32") + state_arr_like = npr.randint(0, 2**31, size=624, dtype="uint32") assert ( com.random_state(state_arr_like).uniform() == npr.RandomState(state_arr_like).uniform() diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index ee451d0288581..44977b9834b80 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -305,7 +305,7 @@ def test_nanmean_overflow(self): # In the previous implementation mean can overflow for int dtypes, it # is now consistent with numpy - for a in [2 ** 55, -(2 ** 55), 20150515061816532]: + for a in [2**55, -(2**55), 20150515061816532]: s = Series(a, index=range(500), dtype=np.int64) result = s.mean() np_result = s.values.mean() @@ -789,7 +789,7 @@ class TestNanvarFixedValues: def setup_method(self, method): # Samples from a normal distribution. self.variance = variance = 3.0 - self.samples = self.prng.normal(scale=variance ** 0.5, size=100000) + self.samples = self.prng.normal(scale=variance**0.5, size=100000) def test_nanvar_all_finite(self): samples = self.samples @@ -811,7 +811,7 @@ def test_nanstd_nans(self): samples[::2] = self.samples actual_std = nanops.nanstd(samples, skipna=True) - tm.assert_almost_equal(actual_std, self.variance ** 0.5, rtol=1e-2) + tm.assert_almost_equal(actual_std, self.variance**0.5, rtol=1e-2) actual_std = nanops.nanvar(samples, skipna=False) tm.assert_almost_equal(actual_std, np.nan, rtol=1e-2) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 0a9d422c45036..fa95693369416 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -982,7 +982,7 @@ def test_datetime_invalid_index(self, values, format, infer): @pytest.mark.parametrize("constructor", [list, tuple, np.array, Index, deque]) def test_to_datetime_cache(self, utc, format, constructor): date = "20130101 00:00:00" - test_dates = [date] * 10 ** 5 + test_dates = [date] * 10**5 data = constructor(test_dates) result = to_datetime(data, utc=utc, format=format, cache=True) @@ -1000,7 +1000,7 @@ def test_to_datetime_from_deque(self): @pytest.mark.parametrize("format", ["%Y%m%d %H:%M:%S", None]) def test_to_datetime_cache_series(self, utc, format): date = "20130101 00:00:00" - test_dates = [date] * 10 ** 5 + test_dates = [date] * 10**5 data = Series(test_dates) result = to_datetime(data, utc=utc, format=format, cache=True) expected = to_datetime(data, utc=utc, format=format, cache=False) @@ -2624,7 +2624,7 @@ def test_no_slicing_errors_in_should_cache(self, listlike): def test_nullable_integer_to_datetime(): # Test for #30050 - ser = Series([1, 2, None, 2 ** 61, None]) + ser = Series([1, 2, None, 2**61, None]) ser = ser.astype("Int64") ser_copy = ser.copy() diff --git a/pandas/tests/tools/test_to_timedelta.py b/pandas/tests/tools/test_to_timedelta.py index ec6fccd42dbc9..cf512463d0473 100644 --- a/pandas/tests/tools/test_to_timedelta.py +++ b/pandas/tests/tools/test_to_timedelta.py @@ -217,7 +217,7 @@ def test_to_timedelta_float(self): # https://github.com/pandas-dev/pandas/issues/25077 arr = np.arange(0, 1, 1e-6)[-10:] result = to_timedelta(arr, unit="s") - expected_asi8 = np.arange(999990000, 10 ** 9, 1000, dtype="int64") + expected_asi8 = np.arange(999990000, 10**9, 1000, dtype="int64") tm.assert_numpy_array_equal(result.asi8, expected_asi8) def test_to_timedelta_coerce_strings_unit(self): diff --git a/pandas/tests/tslibs/test_fields.py b/pandas/tests/tslibs/test_fields.py index 9d0b3ff4fca80..9e6464f7727bd 100644 --- a/pandas/tests/tslibs/test_fields.py +++ b/pandas/tests/tslibs/test_fields.py @@ -8,7 +8,7 @@ @pytest.fixture def dtindex(): - dtindex = np.arange(5, dtype=np.int64) * 10 ** 9 * 3600 * 24 * 32 + dtindex = np.arange(5, dtype=np.int64) * 10**9 * 3600 * 24 * 32 dtindex.flags.writeable = False return dtindex diff --git a/pandas/tests/util/test_assert_extension_array_equal.py b/pandas/tests/util/test_assert_extension_array_equal.py index 545f0dcbf695f..dec10e5b76894 100644 --- a/pandas/tests/util/test_assert_extension_array_equal.py +++ b/pandas/tests/util/test_assert_extension_array_equal.py @@ -35,7 +35,7 @@ def test_assert_extension_array_equal_not_exact(kwargs): @pytest.mark.parametrize("decimals", range(10)) def test_assert_extension_array_equal_less_precise(decimals): - rtol = 0.5 * 10 ** -decimals + rtol = 0.5 * 10**-decimals arr1 = SparseArray([0.5, 0.123456]) arr2 = SparseArray([0.5, 0.123457]) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index 150e7e8f3d738..93a2e4b83e760 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -110,7 +110,7 @@ def test_series_not_equal_metadata_mismatch(kwargs): @pytest.mark.parametrize("dtype", ["float32", "float64", "Float32"]) @pytest.mark.parametrize("decimals", [0, 1, 2, 3, 5, 10]) def test_less_precise(data1, data2, dtype, decimals): - rtol = 10 ** -decimals + rtol = 10**-decimals s1 = Series([data1], dtype=dtype) s2 = Series([data2], dtype=dtype) diff --git a/pandas/tests/util/test_validate_args.py b/pandas/tests/util/test_validate_args.py index db532480efe07..77e6b01ba1180 100644 --- a/pandas/tests/util/test_validate_args.py +++ b/pandas/tests/util/test_validate_args.py @@ -20,8 +20,8 @@ def test_bad_arg_length_max_value_single(): max_length = len(compat_args) + min_fname_arg_count actual_length = len(args) + min_fname_arg_count msg = ( - fr"{_fname}\(\) takes at most {max_length} " - fr"argument \({actual_length} given\)" + rf"{_fname}\(\) takes at most {max_length} " + rf"argument \({actual_length} given\)" ) with pytest.raises(TypeError, match=msg): @@ -36,8 +36,8 @@ def test_bad_arg_length_max_value_multiple(): max_length = len(compat_args) + min_fname_arg_count actual_length = len(args) + min_fname_arg_count msg = ( - fr"{_fname}\(\) takes at most {max_length} " - fr"arguments \({actual_length} given\)" + rf"{_fname}\(\) takes at most {max_length} " + rf"arguments \({actual_length} given\)" ) with pytest.raises(TypeError, match=msg): @@ -49,7 +49,7 @@ def test_not_all_defaults(i): bad_arg = "foo" msg = ( f"the '{bad_arg}' parameter is not supported " - fr"in the pandas implementation of {_fname}\(\)" + rf"in the pandas implementation of {_fname}\(\)" ) compat_args = {"foo": 2, "bar": -1, "baz": 3} diff --git a/pandas/tests/util/test_validate_args_and_kwargs.py b/pandas/tests/util/test_validate_args_and_kwargs.py index 941ba86c61319..54d94d2194909 100644 --- a/pandas/tests/util/test_validate_args_and_kwargs.py +++ b/pandas/tests/util/test_validate_args_and_kwargs.py @@ -15,8 +15,8 @@ def test_invalid_total_length_max_length_one(): actual_length = len(kwargs) + len(args) + min_fname_arg_count msg = ( - fr"{_fname}\(\) takes at most {max_length} " - fr"argument \({actual_length} given\)" + rf"{_fname}\(\) takes at most {max_length} " + rf"argument \({actual_length} given\)" ) with pytest.raises(TypeError, match=msg): @@ -33,8 +33,8 @@ def test_invalid_total_length_max_length_multiple(): actual_length = len(kwargs) + len(args) + min_fname_arg_count msg = ( - fr"{_fname}\(\) takes at most {max_length} " - fr"arguments \({actual_length} given\)" + rf"{_fname}\(\) takes at most {max_length} " + rf"arguments \({actual_length} given\)" ) with pytest.raises(TypeError, match=msg): @@ -49,8 +49,8 @@ def test_missing_args_or_kwargs(args, kwargs): compat_args = {"foo": -5, bad_arg: 1} msg = ( - fr"the '{bad_arg}' parameter is not supported " - fr"in the pandas implementation of {_fname}\(\)" + rf"the '{bad_arg}' parameter is not supported " + rf"in the pandas implementation of {_fname}\(\)" ) with pytest.raises(ValueError, match=msg): @@ -64,7 +64,7 @@ def test_duplicate_argument(): kwargs = {"foo": None, "bar": None} args = (None,) # duplicate value for "foo" - msg = fr"{_fname}\(\) got multiple values for keyword argument 'foo'" + msg = rf"{_fname}\(\) got multiple values for keyword argument 'foo'" with pytest.raises(TypeError, match=msg): validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args) diff --git a/pandas/tests/util/test_validate_kwargs.py b/pandas/tests/util/test_validate_kwargs.py index 0e271ef42ca93..de49cdd5e247d 100644 --- a/pandas/tests/util/test_validate_kwargs.py +++ b/pandas/tests/util/test_validate_kwargs.py @@ -15,7 +15,7 @@ def test_bad_kwarg(): compat_args = {good_arg: "foo", bad_arg + "o": "bar"} kwargs = {good_arg: "foo", bad_arg: "bar"} - msg = fr"{_fname}\(\) got an unexpected keyword argument '{bad_arg}'" + msg = rf"{_fname}\(\) got an unexpected keyword argument '{bad_arg}'" with pytest.raises(TypeError, match=msg): validate_kwargs(_fname, kwargs, compat_args) @@ -25,8 +25,8 @@ def test_bad_kwarg(): def test_not_all_none(i): bad_arg = "foo" msg = ( - fr"the '{bad_arg}' parameter is not supported " - fr"in the pandas implementation of {_fname}\(\)" + rf"the '{bad_arg}' parameter is not supported " + rf"in the pandas implementation of {_fname}\(\)" ) compat_args = {"foo": 1, "bar": "s", "baz": None} diff --git a/requirements-dev.txt b/requirements-dev.txt index 6fd3ac53c50cb..c4f6bb30c59ec 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ python-dateutil>=2.8.1 pytz asv < 0.5.0 cython>=0.29.24 -black==21.5b2 +black==22.3.0 cpplint flake8==4.0.1 flake8-bugbear==21.3.2