From e0e778d01df43c583721e644b79b88d815f3f7fd Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 9 Dec 2019 22:40:13 +0200 Subject: [PATCH 1/3] STY: Underscores for long numbers --- pandas/_libs/testing.pyx | 16 ++-- pandas/core/algorithms.py | 27 ++++--- pandas/core/arrays/categorical.py | 7 +- pandas/core/arrays/timedeltas.py | 2 +- pandas/core/base.py | 2 +- pandas/core/computation/align.py | 10 ++- pandas/core/computation/common.py | 16 ++-- pandas/core/computation/ops.py | 4 +- pandas/tests/io/formats/test_format.py | 103 ++++++++++++------------ pandas/tests/io/parser/test_usecols.py | 33 +++++--- pandas/tests/io/pytables/test_compat.py | 9 ++- 11 files changed, 128 insertions(+), 101 deletions(-) diff --git a/pandas/_libs/testing.pyx b/pandas/_libs/testing.pyx index 8b847350cb1ff..e41914f3aa9ad 100644 --- a/pandas/_libs/testing.pyx +++ b/pandas/_libs/testing.pyx @@ -66,7 +66,8 @@ cpdef assert_almost_equal(a, b, check_less_precise=False, bint check_dtype=True, obj=None, lobj=None, robj=None): - """Check that left and right objects are almost equal. + """ + Check that left and right objects are almost equal. Parameters ---------- @@ -89,7 +90,6 @@ cpdef assert_almost_equal(a, b, Specify right object name being compared, internally used to show appropriate assertion message """ - cdef: int decimal double diff = 0.0 @@ -127,9 +127,9 @@ cpdef assert_almost_equal(a, b, # classes can't be the same, to raise error assert_class_equal(a, b, obj=obj) - assert has_length(a) and has_length(b), ( - f"Can't compare objects without length, one or both is invalid: " - f"({a}, {b})") + assert has_length(a) and has_length(b), ("Can't compare objects without " + "length, one or both is invalid: " + f"({a}, {b})") if a_is_ndarray and b_is_ndarray: na, nb = a.size, b.size @@ -157,7 +157,7 @@ cpdef assert_almost_equal(a, b, else: r = None - raise_assert_detail(obj, f'{obj} length are different', na, nb, r) + raise_assert_detail(obj, f"{obj} length are different", na, nb, r) for i in xrange(len(a)): try: @@ -169,8 +169,8 @@ cpdef assert_almost_equal(a, b, if is_unequal: from pandas.util.testing import raise_assert_detail - msg = (f'{obj} values are different ' - f'({np.round(diff * 100.0 / na, 5)} %)') + msg = (f"{obj} values are different " + f"({np.round(diff * 100.0 / na, 5)} %)") raise_assert_detail(obj, msg, lobj, robj) return True diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 6ccd71a567b02..42cfd9d54ac19 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -391,16 +391,15 @@ def isin(comps, values) -> np.ndarray: ndarray[bool] Same length as `comps`. """ - if not is_list_like(comps): raise TypeError( - "only list-like objects are allowed to be passed" - f" to isin(), you passed a [{type(comps).__name__}]" + "only list-like objects are allowed to be passed " + f"to isin(), you passed a [{type(comps).__name__}]" ) if not is_list_like(values): raise TypeError( - "only list-like objects are allowed to be passed" - f" to isin(), you passed a [{type(values).__name__}]" + "only list-like objects are allowed to be passed " + f"to isin(), you passed a [{type(values).__name__}]" ) if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)): @@ -421,7 +420,7 @@ def isin(comps, values) -> np.ndarray: # GH16012 # Ensure np.in1d doesn't get object types or it *may* throw an exception - if len(comps) > 1000000 and not is_object_dtype(comps): + if len(comps) > 1_000_000 and not is_object_dtype(comps): f = np.in1d elif is_integer_dtype(comps): try: @@ -833,8 +832,8 @@ def mode(values, dropna: bool = True) -> ABCSeries: result = f(values, dropna=dropna) try: result = np.sort(result) - except TypeError as e: - warn(f"Unable to sort modes: {e}") + except TypeError as err: + warn(f"Unable to sort modes: {err}") result = _reconstruct_data(result, original.dtype, original) return Series(result) @@ -1019,7 +1018,8 @@ def quantile(x, q, interpolation_method="fraction"): values = np.sort(x) def _interpolate(a, b, fraction): - """Returns the point at the given fraction between a and b, where + """ + Returns the point at the given fraction between a and b, where 'fraction' must be between 0 and 1. """ return a + (b - a) * fraction @@ -1192,7 +1192,8 @@ def compute(self, method): ) def get_indexer(current_indexer, other_indexer): - """Helper function to concat `current_indexer` and `other_indexer` + """ + Helper function to concat `current_indexer` and `other_indexer` depending on `method` """ if method == "nsmallest": @@ -1660,7 +1661,7 @@ def take_nd( def take_2d_multi(arr, indexer, fill_value=np.nan): """ - Specialized Cython take which sets NaN values in one pass + Specialized Cython take which sets NaN values in one pass. """ # This is only called from one place in DataFrame._reindex_multi, # so we know indexer is well-behaved. @@ -1988,8 +1989,8 @@ def sort_mixed(values): if not is_list_like(codes): raise TypeError( - "Only list-like objects or None are allowed to be" - "passed to safe_sort as codes" + "Only list-like objects or None are allowed to " + "be passed to safe_sort as codes" ) codes = ensure_platform_int(np.asarray(codes)) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 1e470e44ed933..439f36c960617 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -299,7 +299,7 @@ class Categorical(ExtensionArray, PandasObject): # For comparisons, so that numpy uses our implementation if the compare # ops, which raise - __array_priority__ = 1000 + __array_priority__ = 1_000 _dtype = CategoricalDtype(ordered=False) # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = PandasObject._deprecations | frozenset(["tolist", "itemsize"]) @@ -494,14 +494,13 @@ def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike: if is_extension_array_dtype(dtype): return array(self, dtype=dtype, copy=copy) # type: ignore # GH 28770 if is_integer_dtype(dtype) and self.isna().any(): - msg = "Cannot convert float NaN to integer" - raise ValueError(msg) + raise ValueError("Cannot convert float NaN to integer") return np.array(self, dtype=dtype, copy=copy) @cache_readonly def size(self) -> int: """ - return the len of myself + Return the len of myself. """ return self._codes.size diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 56c4a1a201eeb..03699398fddf5 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -157,7 +157,7 @@ class TimedeltaArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps): _typ = "timedeltaarray" _scalar_type = Timedelta - __array_priority__ = 1000 + __array_priority__ = 1_000 # define my properties & methods for delegation _other_ops: List[str] = [] _bool_ops: List[str] = [] diff --git a/pandas/core/base.py b/pandas/core/base.py index 88b8fe405c8e4..e52e66a07eb6d 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -618,7 +618,7 @@ class IndexOpsMixin: """ # ndarray compatibility - __array_priority__ = 1000 + __array_priority__ = 1_000 _deprecations: FrozenSet[str] = frozenset( ["tolist", "item"] # tolist is not deprecated, just suppressed in the __dir__ ) diff --git a/pandas/core/computation/align.py b/pandas/core/computation/align.py index 9390eb47d07ee..bf340783098c5 100644 --- a/pandas/core/computation/align.py +++ b/pandas/core/computation/align.py @@ -35,7 +35,9 @@ def _zip_axes_from_type(typ, new_axes): def _any_pandas_objects(terms) -> bool: - """Check a sequence of terms for instances of PandasObject.""" + """ + Check a sequence of terms for instances of PandasObject. + """ return any(isinstance(term.value, PandasObject) for term in terms) @@ -98,7 +100,7 @@ def _align_core(terms): reindexer_size = len(reindexer) ordm = np.log10(max(1, abs(reindexer_size - term_axis_size))) - if ordm >= 1 and reindexer_size >= 10000: + if ordm >= 1 and reindexer_size >= 10_000: w = ( f"Alignment difference on axis {axis} is larger " f"than an order of magnitude on term {repr(terms[i].name)}, " @@ -116,7 +118,9 @@ def _align_core(terms): def align_terms(terms): - """Align a set of terms""" + """ + Align a set of terms. + """ try: # flatten the parse tree (a nested list, really) terms = list(com.flatten(terms)) diff --git a/pandas/core/computation/common.py b/pandas/core/computation/common.py index da47449d5e62e..994f470942cd1 100644 --- a/pandas/core/computation/common.py +++ b/pandas/core/computation/common.py @@ -9,15 +9,19 @@ def _ensure_decoded(s): - """ if we have bytes, decode them to unicode """ + """ + If we have bytes, decode them to unicode. + """ if isinstance(s, (np.bytes_, bytes)): s = s.decode(get_option("display.encoding")) return s def result_type_many(*arrays_and_dtypes): - """ wrapper around numpy.result_type which overcomes the NPY_MAXARGS (32) - argument limit """ + """ + Wrapper around numpy.result_type which overcomes the NPY_MAXARGS (32) + argument limit. + """ try: return np.result_type(*arrays_and_dtypes) except ValueError: @@ -26,8 +30,10 @@ def result_type_many(*arrays_and_dtypes): def _remove_spaces_column_name(name): - """Check if name contains any spaces, if it contains any spaces - the spaces will be removed and an underscore suffix is added.""" + """ + Check if name contains any spaces, if it contains any spaces + the spaces will be removed and an underscore suffix is added. + """ if not isinstance(name, str) or " " not in name: return name diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index 2215629ec0717..cb166ba65152b 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -506,8 +506,8 @@ def __init__(self, lhs, rhs, **kwargs): if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type): raise TypeError( - f"unsupported operand type(s) for {self.op}:" - f" '{lhs.return_type}' and '{rhs.return_type}'" + f"unsupported operand type(s) for {self.op}: " + f"'{lhs.return_type}' and '{rhs.return_type}'" ) # do not upcast float32s to float64 un-necessarily diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index e875a6f137d80..de0fcb2b06960 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -233,7 +233,7 @@ def test_repr_truncation(self): else: assert "..." not in line - with option_context("display.max_colwidth", 999999): + with option_context("display.max_colwidth", 999_999): assert "..." not in repr(df) with option_context("display.max_colwidth", max_len + 2): @@ -286,11 +286,11 @@ def test_repr_chop_threshold_column_below(self): ) def test_repr_obeys_max_seq_limit(self): - with option_context("display.max_seq_items", 2000): - assert len(printing.pprint_thing(list(range(1000)))) > 1000 + with option_context("display.max_seq_items", 2_000): + assert len(printing.pprint_thing(list(range(1_000)))) > 1_000 with option_context("display.max_seq_items", 5): - assert len(printing.pprint_thing(list(range(1000)))) < 100 + assert len(printing.pprint_thing(list(range(1_000)))) < 100 def test_repr_set(self): assert printing.pprint_thing({1}) == "{1}" @@ -354,10 +354,10 @@ def test_expand_frame_repr(self): def test_repr_non_interactive(self): # in non interactive mode, there can be no dependency on the # result of terminal auto size detection - df = DataFrame("hello", index=range(1000), columns=range(5)) + df = DataFrame("hello", index=range(1_000), columns=range(5)) with option_context( - "mode.sim_interactive", False, "display.width", 0, "display.max_rows", 5000 + "mode.sim_interactive", False, "display.width", 0, "display.max_rows", 5_000 ): assert not has_truncated_repr(df) assert not has_expanded_repr(df) @@ -408,10 +408,10 @@ def test_repr_truncation_column_size(self): # determine size of truncation (...) column df = pd.DataFrame( { - "a": [108480, 30830], - "b": [12345, 12345], - "c": [12345, 12345], - "d": [12345, 12345], + "a": [108_480, 30_830], + "b": [12_345, 12_345], + "c": [12_345, 12_345], + "d": [12_345, 12_345], "e": ["a" * 50] * 2, } ) @@ -719,7 +719,7 @@ def test_east_asian_unicode_false(self): # mid col df = DataFrame( - {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33333, 4]}, + {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33_333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -755,7 +755,7 @@ def test_east_asian_unicode_false(self): # column name df = DataFrame( - {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33333, 4]}, + {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33_333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -857,7 +857,7 @@ def test_east_asian_unicode_true(self): # mid col df = DataFrame( - {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33333, 4]}, + {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33_333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -869,7 +869,7 @@ def test_east_asian_unicode_true(self): # last col df = DataFrame( - {"a": [1, 222, 33333, 4], "b": ["あ", "いいい", "う", "ええええええ"]}, + {"a": [1, 222, 33_333, 4], "b": ["あ", "いいい", "う", "ええええええ"]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -895,7 +895,7 @@ def test_east_asian_unicode_true(self): # column name df = DataFrame( - {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33333, 4]}, + {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33_333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -1002,7 +1002,7 @@ def test_east_asian_unicode_true(self): # ambiguous unicode df = DataFrame( - {"b": ["あ", "いいい", "¡¡", "ええええええ"], "あああああ": [1, 222, 33333, 4]}, + {"b": ["あ", "いいい", "¡¡", "ええええええ"], "あああああ": [1, 222, 33_333, 4]}, index=["a", "bb", "c", "¡¡¡"], ) expected = ( @@ -1339,7 +1339,7 @@ def test_wide_repr_wide_long_columns(self): assert "ddddd" in result def test_long_series(self): - n = 1000 + n = 1_000 s = Series( np.random.randint(-50, 50, n), index=["s{x:04d}".format(x=x) for x in range(n)], @@ -1545,7 +1545,7 @@ def test_to_string_float_formatting(self): ) df = DataFrame( - {"x": [0, 0.25, 3456.000, 12e45, 1.64e6, 1.7e8, 1.253456, np.pi, -1e6]} + {"x": [0, 0.25, 3_456.000, 12e45, 1.64e6, 1.7e8, 1.253_456, np.pi, -1e6]} ) df_s = df.to_string() @@ -1566,7 +1566,7 @@ def test_to_string_float_formatting(self): ) assert df_s == expected - df = DataFrame({"x": [3234, 0.253]}) + df = DataFrame({"x": [3_234, 0.253]}) df_s = df.to_string() expected = " x\n0 3234.000\n1 0.253" @@ -1587,7 +1587,7 @@ def test_to_string_float_formatting(self): def test_to_string_float_format_no_fixed_width(self): # GH 21625 - df = DataFrame({"x": [0.19999]}) + df = DataFrame({"x": [0.19_999]}) expected = " x\n0 0.200" assert df.to_string(float_format="%.3f") == expected @@ -1636,9 +1636,9 @@ def test_to_string_complex_float_formatting(self): df = DataFrame( { "x": [ - (0.4467846931321966 + 0.0715185102060818j), - (0.2739442392974528 + 0.23515228785438969j), - (0.26974928742135185 + 0.3250604054898979j), + (0.4_467_846_931_321_966 + 0.0_715_185_102_060_818j), + (0.2_739_442_392_974_528 + 0.23_515_228_785_438_969j), + (0.26_974_928_742_135_185 + 0.3_250_604_054_898_979j), (-1j), ] } @@ -1690,7 +1690,7 @@ def test_to_string_index_formatter(self): def test_to_string_left_justify_cols(self): tm.reset_display_options() - df = DataFrame({"x": [3234, 0.253]}) + df = DataFrame({"x": [3_234, 0.253]}) df_s = df.to_string(justify="left") expected = " x \n0 3234.000\n1 0.253" assert df_s == expected @@ -1699,7 +1699,7 @@ def test_to_string_format_na(self): tm.reset_display_options() df = DataFrame( { - "A": [np.nan, -1, -2.1234, 3, 4], + "A": [np.nan, -1, -2.1_234, 3, 4], "B": [np.nan, "foo", "foooo", "fooooo", "bar"], } ) @@ -1738,7 +1738,7 @@ def test_to_string_format_inf(self): tm.reset_display_options() df = DataFrame( { - "A": [-np.inf, np.inf, -1, -2.1234, 3, 4], + "A": [-np.inf, np.inf, -1, -2.1_234, 3, 4], "B": [-np.inf, np.inf, "foo", "foooo", "fooooo", "bar"], } ) @@ -2076,11 +2076,11 @@ def __getitem__(self, key): def test_float_trim_zeros(self): vals = [ - 2.08430917305e10, - 3.52205017305e10, - 2.30674817305e10, - 2.03954217305e10, - 5.59897817305e10, + 2.08_430_917_305e10, + 3.52_205_017_305e10, + 2.30_674_817_305e10, + 2.03_954_217_305e10, + 5.59_897_817_305e10, ] skip = True for line in repr(DataFrame({"A": vals})).split("\n")[:-2]: @@ -2140,7 +2140,7 @@ def test_repr_unicode(self): s = Series(["\u03c3"] * 10) repr(s) - a = Series(["\u05d0"] * 1000) + a = Series(["\u05d0"] * 1_000) a.name = "title1" repr(a) @@ -2202,7 +2202,7 @@ def test_to_string_mixed(self): assert result == expected def test_to_string_float_na_spacing(self): - s = Series([0.0, 1.5678, 2.0, -3.0, 4.0]) + s = Series([0.0, 1.5_678, 2.0, -3.0, 4.0]) s[::2] = np.nan result = s.to_string() @@ -2261,7 +2261,7 @@ def test_east_asian_unicode_series(self): idx = pd.MultiIndex.from_tuples( [("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")] ) - s = Series([1, 22, 3333, 44444], index=idx) + s = Series([1, 22, 3_333, 44_444], index=idx) expected = ( "あ いい 1\n" "う え 22\n" @@ -2271,7 +2271,7 @@ def test_east_asian_unicode_series(self): assert repr(s) == expected # object dtype, shorter than unicode repr - s = Series([1, 22, 3333, 44444], index=[1, "AB", np.nan, "あああ"]) + s = Series([1, 22, 3_333, 44_444], index=[1, "AB", np.nan, "あああ"]) expected = ( "1 1\nAB 22\nNaN 3333\nあああ 44444\ndtype: int64" ) @@ -2279,7 +2279,7 @@ def test_east_asian_unicode_series(self): # object dtype, longer than unicode repr s = Series( - [1, 22, 3333, 44444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] + [1, 22, 3_333, 44_444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] ) expected = ( "1 1\n" @@ -2356,7 +2356,7 @@ def test_east_asian_unicode_series(self): idx = pd.MultiIndex.from_tuples( [("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")] ) - s = Series([1, 22, 3333, 44444], index=idx) + s = Series([1, 22, 3_333, 44_444], index=idx) expected = ( "あ いい 1\n" "う え 22\n" @@ -2367,7 +2367,7 @@ def test_east_asian_unicode_series(self): assert repr(s) == expected # object dtype, shorter than unicode repr - s = Series([1, 22, 3333, 44444], index=[1, "AB", np.nan, "あああ"]) + s = Series([1, 22, 3_333, 44_444], index=[1, "AB", np.nan, "あああ"]) expected = ( "1 1\nAB 22\nNaN 3333\n" "あああ 44444\ndtype: int64" @@ -2376,7 +2376,8 @@ def test_east_asian_unicode_series(self): # object dtype, longer than unicode repr s = Series( - [1, 22, 3333, 44444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] + [1, 22, 3_333, 44_444], + index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"], ) expected = ( "1 1\n" @@ -2419,11 +2420,11 @@ def test_east_asian_unicode_series(self): def test_float_trim_zeros(self): vals = [ - 2.08430917305e10, - 3.52205017305e10, - 2.30674817305e10, - 2.03954217305e10, - 5.59897817305e10, + 2.08_430_917_305e10, + 3.52_205_017_305e10, + 2.30_674_817_305e10, + 2.03_954_217_305e10, + 5.59_897_817_305e10, ] for line in repr(Series(vals)).split("\n"): if line.startswith("dtype:"): @@ -2478,7 +2479,7 @@ def test_timedelta64(self): from datetime import datetime, timedelta - Series(np.array([1100, 20], dtype="timedelta64[ns]")).to_string() + Series(np.array([11_00, 20], dtype="timedelta64[ns]")).to_string() s = Series(date_range("2012-1-1", periods=3, freq="D")) @@ -2623,7 +2624,7 @@ def test_max_multi_index_display(self): # Make sure #8532 is fixed def test_consistent_format(self): - s = pd.Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9999, 1, 1] * 10) + s = pd.Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9_999, 1, 1] * 10) with option_context("display.max_rows", 10, "display.show_dimensions", False): res = repr(s) exp = ( @@ -2823,19 +2824,19 @@ def test_output_significant_digits(self): "col1": [ 9.999e-8, 1e-7, - 1.0001e-7, + 1.0_001e-7, 2e-7, 4.999e-7, 5e-7, - 5.0001e-7, + 5.0_001e-7, 6e-7, 9.999e-7, 1e-6, - 1.0001e-6, + 1.0_001e-6, 2e-6, 4.999e-6, 5e-6, - 5.0001e-6, + 5.0_001e-6, 6e-6, ] } @@ -2890,7 +2891,7 @@ def test_too_long(self): with pd.option_context("display.precision", 4): # need both a number > 1e6 and something that normally formats to # having length > display.precision + 6 - df = pd.DataFrame(dict(x=[12345.6789])) + df = pd.DataFrame(dict(x=[12_345.6_789])) assert str(df) == " x\n0 12345.6789" df = pd.DataFrame(dict(x=[2e6])) assert str(df) == " x\n0 2000000.0" diff --git a/pandas/tests/io/parser/test_usecols.py b/pandas/tests/io/parser/test_usecols.py index afe19608ea5c6..741ef90cb3153 100644 --- a/pandas/tests/io/parser/test_usecols.py +++ b/pandas/tests/io/parser/test_usecols.py @@ -197,9 +197,12 @@ def test_usecols_with_whitespace(all_parsers): "usecols,expected", [ # Column selection by index. - ([0, 1], DataFrame(data=[[1000, 2000], [4000, 5000]], columns=["2", "0"])), + ([0, 1], DataFrame(data=[[1_000, 2_000], [4_000, 5_000]], columns=["2", "0"])), # Column selection by name. - (["0", "1"], DataFrame(data=[[2000, 3000], [5000, 6000]], columns=["0", "1"])), + ( + ["0", "1"], + DataFrame(data=[[2_000, 3_000], [5_000, 6_000]], columns=["0", "1"]), + ), ], ) def test_usecols_with_integer_like_header(all_parsers, usecols, expected): @@ -249,7 +252,7 @@ def test_usecols_with_parse_dates2(all_parsers): ], name="date", ) - cols = {"values": [1032.43, 1042.54, 1051.65]} + cols = {"values": [1_032.43, 1_042.54, 1_051.65]} expected = DataFrame(cols, index=index) result = parser.read_csv( @@ -349,7 +352,11 @@ def test_usecols_with_unicode_strings(all_parsers): parser = all_parsers exp_data = { - "AAA": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002}, + "AAA": { + 0: 0.056_674_972_999_999_997, + 1: 2.6_132_309_819_999_997, + 2: 3.5_689_350_380_000_002, + }, "BBB": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -367,7 +374,11 @@ def test_usecols_with_single_byte_unicode_strings(all_parsers): parser = all_parsers exp_data = { - "A": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002}, + "A": { + 0: 0.056_674_972_999_999_997, + 1: 2.6_132_309_819_999_997, + 2: 3.5_689_350_380_000_002, + }, "B": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -397,7 +408,11 @@ def test_usecols_with_multi_byte_characters(all_parsers, usecols): parser = all_parsers exp_data = { - "あああ": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002}, + "あああ": { + 0: 0.056_674_972_999_999_997, + 1: 2.6_132_309_819_999_997, + 2: 3.5_689_350_380_000_002, + }, "いい": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -434,9 +449,9 @@ def test_np_array_usecols(all_parsers): DataFrame( { "AaA": { - 0: 0.056674972999999997, - 1: 2.6132309819999997, - 2: 3.5689350380000002, + 0: 0.056_674_972_999_999_997, + 1: 2.6_132_309_819_999_997, + 2: 3.5_689_350_380_000_002, }, "bBb": {0: 8, 1: 2, 2: 7}, "ddd": {0: "a", 1: "b", 2: "a"}, diff --git a/pandas/tests/io/pytables/test_compat.py b/pandas/tests/io/pytables/test_compat.py index 1e320e12a4a53..a82e21532eddb 100644 --- a/pandas/tests/io/pytables/test_compat.py +++ b/pandas/tests/io/pytables/test_compat.py @@ -9,21 +9,22 @@ @pytest.fixture def pytables_hdf5_file(): - """Use PyTables to create a simple HDF5 file.""" - + """ + Use PyTables to create a simple HDF5 file. + """ table_schema = { "c0": tables.Time64Col(pos=0), "c1": tables.StringCol(5, pos=1), "c2": tables.Int64Col(pos=2), } - t0 = 1561105000.0 + t0 = 1_561_105_000.0 testsamples = [ {"c0": t0, "c1": "aaaaa", "c2": 1}, {"c0": t0 + 1, "c1": "bbbbb", "c2": 2}, {"c0": t0 + 2, "c1": "ccccc", "c2": 10 ** 5}, - {"c0": t0 + 3, "c1": "ddddd", "c2": 4294967295}, + {"c0": t0 + 3, "c1": "ddddd", "c2": 4_294_967_295}, ] objname = "pandas_test_timeseries" From eddfb8f1c521769176359364bbfedaf937361b6d Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Tue, 10 Dec 2019 13:28:59 +0200 Subject: [PATCH 2/3] Decimal --- pandas/core/arrays/categorical.py | 2 +- pandas/core/arrays/timedeltas.py | 2 +- pandas/core/base.py | 2 +- pandas/tests/io/formats/test_format.py | 76 +++++++++++++------------- pandas/tests/io/parser/test_usecols.py | 33 +++-------- 5 files changed, 50 insertions(+), 65 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 439f36c960617..7170aec3820a8 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -299,7 +299,7 @@ class Categorical(ExtensionArray, PandasObject): # For comparisons, so that numpy uses our implementation if the compare # ops, which raise - __array_priority__ = 1_000 + __array_priority__ = 1000 _dtype = CategoricalDtype(ordered=False) # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = PandasObject._deprecations | frozenset(["tolist", "itemsize"]) diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 03699398fddf5..56c4a1a201eeb 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -157,7 +157,7 @@ class TimedeltaArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps): _typ = "timedeltaarray" _scalar_type = Timedelta - __array_priority__ = 1_000 + __array_priority__ = 1000 # define my properties & methods for delegation _other_ops: List[str] = [] _bool_ops: List[str] = [] diff --git a/pandas/core/base.py b/pandas/core/base.py index e52e66a07eb6d..88b8fe405c8e4 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -618,7 +618,7 @@ class IndexOpsMixin: """ # ndarray compatibility - __array_priority__ = 1_000 + __array_priority__ = 1000 _deprecations: FrozenSet[str] = frozenset( ["tolist", "item"] # tolist is not deprecated, just suppressed in the __dir__ ) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index de0fcb2b06960..defa99313d73a 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -286,11 +286,11 @@ def test_repr_chop_threshold_column_below(self): ) def test_repr_obeys_max_seq_limit(self): - with option_context("display.max_seq_items", 2_000): - assert len(printing.pprint_thing(list(range(1_000)))) > 1_000 + with option_context("display.max_seq_items", 2000): + assert len(printing.pprint_thing(list(range(1000)))) > 1000 with option_context("display.max_seq_items", 5): - assert len(printing.pprint_thing(list(range(1_000)))) < 100 + assert len(printing.pprint_thing(list(range(1000)))) < 100 def test_repr_set(self): assert printing.pprint_thing({1}) == "{1}" @@ -354,10 +354,10 @@ def test_expand_frame_repr(self): def test_repr_non_interactive(self): # in non interactive mode, there can be no dependency on the # result of terminal auto size detection - df = DataFrame("hello", index=range(1_000), columns=range(5)) + df = DataFrame("hello", index=range(1000), columns=range(5)) with option_context( - "mode.sim_interactive", False, "display.width", 0, "display.max_rows", 5_000 + "mode.sim_interactive", False, "display.width", 0, "display.max_rows", 5000 ): assert not has_truncated_repr(df) assert not has_expanded_repr(df) @@ -1339,7 +1339,7 @@ def test_wide_repr_wide_long_columns(self): assert "ddddd" in result def test_long_series(self): - n = 1_000 + n = 1000 s = Series( np.random.randint(-50, 50, n), index=["s{x:04d}".format(x=x) for x in range(n)], @@ -1545,7 +1545,7 @@ def test_to_string_float_formatting(self): ) df = DataFrame( - {"x": [0, 0.25, 3_456.000, 12e45, 1.64e6, 1.7e8, 1.253_456, np.pi, -1e6]} + {"x": [0, 0.25, 3456.000, 12e45, 1.64e6, 1.7e8, 1.253_456, np.pi, -1e6]} ) df_s = df.to_string() @@ -1566,7 +1566,7 @@ def test_to_string_float_formatting(self): ) assert df_s == expected - df = DataFrame({"x": [3_234, 0.253]}) + df = DataFrame({"x": [3234, 0.253]}) df_s = df.to_string() expected = " x\n0 3234.000\n1 0.253" @@ -1636,9 +1636,9 @@ def test_to_string_complex_float_formatting(self): df = DataFrame( { "x": [ - (0.4_467_846_931_321_966 + 0.0_715_185_102_060_818j), - (0.2_739_442_392_974_528 + 0.23_515_228_785_438_969j), - (0.26_974_928_742_135_185 + 0.3_250_604_054_898_979j), + (0.4467846931321966 + 0.0715185102060818j), + (0.2739442392974528 + 0.23515228785438969j), + (0.26974928742135185 + 0.3250604054898979j), (-1j), ] } @@ -1690,7 +1690,7 @@ def test_to_string_index_formatter(self): def test_to_string_left_justify_cols(self): tm.reset_display_options() - df = DataFrame({"x": [3_234, 0.253]}) + df = DataFrame({"x": [3234, 0.253]}) df_s = df.to_string(justify="left") expected = " x \n0 3234.000\n1 0.253" assert df_s == expected @@ -1699,7 +1699,7 @@ def test_to_string_format_na(self): tm.reset_display_options() df = DataFrame( { - "A": [np.nan, -1, -2.1_234, 3, 4], + "A": [np.nan, -1, -2.1234, 3, 4], "B": [np.nan, "foo", "foooo", "fooooo", "bar"], } ) @@ -1738,7 +1738,7 @@ def test_to_string_format_inf(self): tm.reset_display_options() df = DataFrame( { - "A": [-np.inf, np.inf, -1, -2.1_234, 3, 4], + "A": [-np.inf, np.inf, -1, -2.1234, 3, 4], "B": [-np.inf, np.inf, "foo", "foooo", "fooooo", "bar"], } ) @@ -2076,11 +2076,11 @@ def __getitem__(self, key): def test_float_trim_zeros(self): vals = [ - 2.08_430_917_305e10, - 3.52_205_017_305e10, - 2.30_674_817_305e10, - 2.03_954_217_305e10, - 5.59_897_817_305e10, + 2.08430917305e10, + 3.52205017305e10, + 2.30674817305e10, + 2.03954217305e10, + 5.59897817305e10, ] skip = True for line in repr(DataFrame({"A": vals})).split("\n")[:-2]: @@ -2140,7 +2140,7 @@ def test_repr_unicode(self): s = Series(["\u03c3"] * 10) repr(s) - a = Series(["\u05d0"] * 1_000) + a = Series(["\u05d0"] * 1000) a.name = "title1" repr(a) @@ -2202,7 +2202,7 @@ def test_to_string_mixed(self): assert result == expected def test_to_string_float_na_spacing(self): - s = Series([0.0, 1.5_678, 2.0, -3.0, 4.0]) + s = Series([0.0, 1.5678, 2.0, -3.0, 4.0]) s[::2] = np.nan result = s.to_string() @@ -2261,7 +2261,7 @@ def test_east_asian_unicode_series(self): idx = pd.MultiIndex.from_tuples( [("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")] ) - s = Series([1, 22, 3_333, 44_444], index=idx) + s = Series([1, 22, 3333, 44_444], index=idx) expected = ( "あ いい 1\n" "う え 22\n" @@ -2271,7 +2271,7 @@ def test_east_asian_unicode_series(self): assert repr(s) == expected # object dtype, shorter than unicode repr - s = Series([1, 22, 3_333, 44_444], index=[1, "AB", np.nan, "あああ"]) + s = Series([1, 22, 3333, 44_444], index=[1, "AB", np.nan, "あああ"]) expected = ( "1 1\nAB 22\nNaN 3333\nあああ 44444\ndtype: int64" ) @@ -2279,7 +2279,7 @@ def test_east_asian_unicode_series(self): # object dtype, longer than unicode repr s = Series( - [1, 22, 3_333, 44_444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] + [1, 22, 3333, 44_444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] ) expected = ( "1 1\n" @@ -2356,7 +2356,7 @@ def test_east_asian_unicode_series(self): idx = pd.MultiIndex.from_tuples( [("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")] ) - s = Series([1, 22, 3_333, 44_444], index=idx) + s = Series([1, 22, 3333, 44_444], index=idx) expected = ( "あ いい 1\n" "う え 22\n" @@ -2367,7 +2367,7 @@ def test_east_asian_unicode_series(self): assert repr(s) == expected # object dtype, shorter than unicode repr - s = Series([1, 22, 3_333, 44_444], index=[1, "AB", np.nan, "あああ"]) + s = Series([1, 22, 3333, 44_444], index=[1, "AB", np.nan, "あああ"]) expected = ( "1 1\nAB 22\nNaN 3333\n" "あああ 44444\ndtype: int64" @@ -2376,7 +2376,7 @@ def test_east_asian_unicode_series(self): # object dtype, longer than unicode repr s = Series( - [1, 22, 3_333, 44_444], + [1, 22, 3333, 44_444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"], ) expected = ( @@ -2420,11 +2420,11 @@ def test_east_asian_unicode_series(self): def test_float_trim_zeros(self): vals = [ - 2.08_430_917_305e10, - 3.52_205_017_305e10, - 2.30_674_817_305e10, - 2.03_954_217_305e10, - 5.59_897_817_305e10, + 2.08430917305e10, + 3.52205017305e10, + 2.30674817305e10, + 2.03954217305e10, + 5.59897817305e10, ] for line in repr(Series(vals)).split("\n"): if line.startswith("dtype:"): @@ -2624,7 +2624,7 @@ def test_max_multi_index_display(self): # Make sure #8532 is fixed def test_consistent_format(self): - s = pd.Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9_999, 1, 1] * 10) + s = pd.Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9999, 1, 1] * 10) with option_context("display.max_rows", 10, "display.show_dimensions", False): res = repr(s) exp = ( @@ -2824,19 +2824,19 @@ def test_output_significant_digits(self): "col1": [ 9.999e-8, 1e-7, - 1.0_001e-7, + 1.0001e-7, 2e-7, 4.999e-7, 5e-7, - 5.0_001e-7, + 5.0001e-7, 6e-7, 9.999e-7, 1e-6, - 1.0_001e-6, + 1.0001e-6, 2e-6, 4.999e-6, 5e-6, - 5.0_001e-6, + 5.0001e-6, 6e-6, ] } @@ -2891,7 +2891,7 @@ def test_too_long(self): with pd.option_context("display.precision", 4): # need both a number > 1e6 and something that normally formats to # having length > display.precision + 6 - df = pd.DataFrame(dict(x=[12_345.6_789])) + df = pd.DataFrame(dict(x=[12_345.6789])) assert str(df) == " x\n0 12345.6789" df = pd.DataFrame(dict(x=[2e6])) assert str(df) == " x\n0 2000000.0" diff --git a/pandas/tests/io/parser/test_usecols.py b/pandas/tests/io/parser/test_usecols.py index 741ef90cb3153..b6b370295bac7 100644 --- a/pandas/tests/io/parser/test_usecols.py +++ b/pandas/tests/io/parser/test_usecols.py @@ -197,12 +197,9 @@ def test_usecols_with_whitespace(all_parsers): "usecols,expected", [ # Column selection by index. - ([0, 1], DataFrame(data=[[1_000, 2_000], [4_000, 5_000]], columns=["2", "0"])), + ([0, 1], DataFrame(data=[[1000, 2000], [4000, 5000]], columns=["2", "0"])), # Column selection by name. - ( - ["0", "1"], - DataFrame(data=[[2_000, 3_000], [5_000, 6_000]], columns=["0", "1"]), - ), + (["0", "1"], DataFrame(data=[[2000, 3000], [5000, 6000]], columns=["0", "1"]),), ], ) def test_usecols_with_integer_like_header(all_parsers, usecols, expected): @@ -252,7 +249,7 @@ def test_usecols_with_parse_dates2(all_parsers): ], name="date", ) - cols = {"values": [1_032.43, 1_042.54, 1_051.65]} + cols = {"values": [1032.43, 1042.54, 1051.65]} expected = DataFrame(cols, index=index) result = parser.read_csv( @@ -352,11 +349,7 @@ def test_usecols_with_unicode_strings(all_parsers): parser = all_parsers exp_data = { - "AAA": { - 0: 0.056_674_972_999_999_997, - 1: 2.6_132_309_819_999_997, - 2: 3.5_689_350_380_000_002, - }, + "AAA": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002,}, "BBB": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -374,11 +367,7 @@ def test_usecols_with_single_byte_unicode_strings(all_parsers): parser = all_parsers exp_data = { - "A": { - 0: 0.056_674_972_999_999_997, - 1: 2.6_132_309_819_999_997, - 2: 3.5_689_350_380_000_002, - }, + "A": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002,}, "B": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -408,11 +397,7 @@ def test_usecols_with_multi_byte_characters(all_parsers, usecols): parser = all_parsers exp_data = { - "あああ": { - 0: 0.056_674_972_999_999_997, - 1: 2.6_132_309_819_999_997, - 2: 3.5_689_350_380_000_002, - }, + "あああ": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002,}, "いい": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -449,9 +434,9 @@ def test_np_array_usecols(all_parsers): DataFrame( { "AaA": { - 0: 0.056_674_972_999_999_997, - 1: 2.6_132_309_819_999_997, - 2: 3.5_689_350_380_000_002, + 0: 0.056674972999999997, + 1: 2.6132309819999997, + 2: 3.5689350380000002, }, "bBb": {0: 8, 1: 2, 2: 7}, "ddd": {0: "a", 1: "b", 2: "a"}, From 35a430109f96da0e99f177325253bb932f2937b1 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Tue, 10 Dec 2019 13:46:55 +0200 Subject: [PATCH 3/3] Less than 7 digits --- pandas/core/computation/align.py | 2 +- pandas/tests/io/formats/test_format.py | 42 +++++++++++++------------- pandas/tests/io/parser/test_usecols.py | 6 ++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pandas/core/computation/align.py b/pandas/core/computation/align.py index bf340783098c5..57348ad3b81a0 100644 --- a/pandas/core/computation/align.py +++ b/pandas/core/computation/align.py @@ -100,7 +100,7 @@ def _align_core(terms): reindexer_size = len(reindexer) ordm = np.log10(max(1, abs(reindexer_size - term_axis_size))) - if ordm >= 1 and reindexer_size >= 10_000: + if ordm >= 1 and reindexer_size >= 10000: w = ( f"Alignment difference on axis {axis} is larger " f"than an order of magnitude on term {repr(terms[i].name)}, " diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index defa99313d73a..6fd813c086982 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -233,7 +233,7 @@ def test_repr_truncation(self): else: assert "..." not in line - with option_context("display.max_colwidth", 999_999): + with option_context("display.max_colwidth", 999999): assert "..." not in repr(df) with option_context("display.max_colwidth", max_len + 2): @@ -408,10 +408,10 @@ def test_repr_truncation_column_size(self): # determine size of truncation (...) column df = pd.DataFrame( { - "a": [108_480, 30_830], - "b": [12_345, 12_345], - "c": [12_345, 12_345], - "d": [12_345, 12_345], + "a": [108480, 30830], + "b": [12345, 12345], + "c": [12345, 12345], + "d": [12345, 12345], "e": ["a" * 50] * 2, } ) @@ -719,7 +719,7 @@ def test_east_asian_unicode_false(self): # mid col df = DataFrame( - {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33_333, 4]}, + {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -755,7 +755,7 @@ def test_east_asian_unicode_false(self): # column name df = DataFrame( - {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33_333, 4]}, + {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -857,7 +857,7 @@ def test_east_asian_unicode_true(self): # mid col df = DataFrame( - {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33_333, 4]}, + {"a": ["あ", "いいい", "う", "ええええええ"], "b": [1, 222, 33333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -869,7 +869,7 @@ def test_east_asian_unicode_true(self): # last col df = DataFrame( - {"a": [1, 222, 33_333, 4], "b": ["あ", "いいい", "う", "ええええええ"]}, + {"a": [1, 222, 33333, 4], "b": ["あ", "いいい", "う", "ええええええ"]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -895,7 +895,7 @@ def test_east_asian_unicode_true(self): # column name df = DataFrame( - {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33_333, 4]}, + {"b": ["あ", "いいい", "う", "ええええええ"], "あああああ": [1, 222, 33333, 4]}, index=["a", "bb", "c", "ddd"], ) expected = ( @@ -1002,7 +1002,7 @@ def test_east_asian_unicode_true(self): # ambiguous unicode df = DataFrame( - {"b": ["あ", "いいい", "¡¡", "ええええええ"], "あああああ": [1, 222, 33_333, 4]}, + {"b": ["あ", "いいい", "¡¡", "ええええええ"], "あああああ": [1, 222, 33333, 4]}, index=["a", "bb", "c", "¡¡¡"], ) expected = ( @@ -1545,7 +1545,7 @@ def test_to_string_float_formatting(self): ) df = DataFrame( - {"x": [0, 0.25, 3456.000, 12e45, 1.64e6, 1.7e8, 1.253_456, np.pi, -1e6]} + {"x": [0, 0.25, 3456.000, 12e45, 1.64e6, 1.7e8, 1.253456, np.pi, -1e6]} ) df_s = df.to_string() @@ -1587,7 +1587,7 @@ def test_to_string_float_formatting(self): def test_to_string_float_format_no_fixed_width(self): # GH 21625 - df = DataFrame({"x": [0.19_999]}) + df = DataFrame({"x": [0.19999]}) expected = " x\n0 0.200" assert df.to_string(float_format="%.3f") == expected @@ -2261,7 +2261,7 @@ def test_east_asian_unicode_series(self): idx = pd.MultiIndex.from_tuples( [("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")] ) - s = Series([1, 22, 3333, 44_444], index=idx) + s = Series([1, 22, 3333, 44444], index=idx) expected = ( "あ いい 1\n" "う え 22\n" @@ -2271,7 +2271,7 @@ def test_east_asian_unicode_series(self): assert repr(s) == expected # object dtype, shorter than unicode repr - s = Series([1, 22, 3333, 44_444], index=[1, "AB", np.nan, "あああ"]) + s = Series([1, 22, 3333, 44444], index=[1, "AB", np.nan, "あああ"]) expected = ( "1 1\nAB 22\nNaN 3333\nあああ 44444\ndtype: int64" ) @@ -2279,7 +2279,7 @@ def test_east_asian_unicode_series(self): # object dtype, longer than unicode repr s = Series( - [1, 22, 3333, 44_444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] + [1, 22, 3333, 44444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"] ) expected = ( "1 1\n" @@ -2356,7 +2356,7 @@ def test_east_asian_unicode_series(self): idx = pd.MultiIndex.from_tuples( [("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")] ) - s = Series([1, 22, 3333, 44_444], index=idx) + s = Series([1, 22, 3333, 44444], index=idx) expected = ( "あ いい 1\n" "う え 22\n" @@ -2367,7 +2367,7 @@ def test_east_asian_unicode_series(self): assert repr(s) == expected # object dtype, shorter than unicode repr - s = Series([1, 22, 3333, 44_444], index=[1, "AB", np.nan, "あああ"]) + s = Series([1, 22, 3333, 44444], index=[1, "AB", np.nan, "あああ"]) expected = ( "1 1\nAB 22\nNaN 3333\n" "あああ 44444\ndtype: int64" @@ -2376,7 +2376,7 @@ def test_east_asian_unicode_series(self): # object dtype, longer than unicode repr s = Series( - [1, 22, 3333, 44_444], + [1, 22, 3333, 44444], index=[1, "AB", pd.Timestamp("2011-01-01"), "あああ"], ) expected = ( @@ -2479,7 +2479,7 @@ def test_timedelta64(self): from datetime import datetime, timedelta - Series(np.array([11_00, 20], dtype="timedelta64[ns]")).to_string() + Series(np.array([1100, 20], dtype="timedelta64[ns]")).to_string() s = Series(date_range("2012-1-1", periods=3, freq="D")) @@ -2891,7 +2891,7 @@ def test_too_long(self): with pd.option_context("display.precision", 4): # need both a number > 1e6 and something that normally formats to # having length > display.precision + 6 - df = pd.DataFrame(dict(x=[12_345.6789])) + df = pd.DataFrame(dict(x=[12345.6789])) assert str(df) == " x\n0 12345.6789" df = pd.DataFrame(dict(x=[2e6])) assert str(df) == " x\n0 2000000.0" diff --git a/pandas/tests/io/parser/test_usecols.py b/pandas/tests/io/parser/test_usecols.py index b6b370295bac7..539fdf2470c51 100644 --- a/pandas/tests/io/parser/test_usecols.py +++ b/pandas/tests/io/parser/test_usecols.py @@ -349,7 +349,7 @@ def test_usecols_with_unicode_strings(all_parsers): parser = all_parsers exp_data = { - "AAA": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002,}, + "AAA": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002}, "BBB": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -367,7 +367,7 @@ def test_usecols_with_single_byte_unicode_strings(all_parsers): parser = all_parsers exp_data = { - "A": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002,}, + "A": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002}, "B": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data) @@ -397,7 +397,7 @@ def test_usecols_with_multi_byte_characters(all_parsers, usecols): parser = all_parsers exp_data = { - "あああ": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002,}, + "あああ": {0: 0.056674972999999997, 1: 2.6132309819999997, 2: 3.5689350380000002}, "いい": {0: 8, 1: 2, 2: 7}, } expected = DataFrame(exp_data)