diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index c05eeb761abcf..34e01e55d2028 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1076,9 +1076,9 @@ def tz_localize(self, tz, ambiguous="raise", nonexistent="raise"): nonexistent, timedelta ): raise ValueError( - "The nonexistent argument must be one of 'raise'," - " 'NaT', 'shift_forward', 'shift_backward' or" - " a timedelta object" + "The nonexistent argument must be one of 'raise', " + "'NaT', 'shift_forward', 'shift_backward' or " + "a timedelta object" ) if self.tz is not None: @@ -1151,7 +1151,7 @@ def normalize(self): """ if self.tz is None or timezones.is_utc(self.tz): not_null = ~self.isna() - DAY_NS = ccalendar.DAY_SECONDS * 1000000000 + DAY_NS = ccalendar.DAY_SECONDS * 1_000_000_000 new_values = self.asi8.copy() adjustment = new_values[not_null] % DAY_NS new_values[not_null] = new_values[not_null] - adjustment @@ -1767,7 +1767,7 @@ def to_julian_date(self): + np.floor(year / 4) - np.floor(year / 100) + np.floor(year / 400) - + 1721118.5 + + 1_721_118.5 + ( self.hour + self.minute / 60.0 @@ -2031,7 +2031,7 @@ def maybe_convert_dtype(data, copy): # Note: without explicitly raising here, PeriodIndex # test_setops.test_join_does_not_recur fails raise TypeError( - "Passing PeriodDtype data is invalid. Use `data.to_timestamp()` instead" + "Passing PeriodDtype data is invalid. Use `data.to_timestamp()` instead" ) elif is_categorical_dtype(data): diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 413d7a8f3afc0..b8d86d9e295fe 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -593,7 +593,6 @@ def _repr_fits_horizontal_(self, ignore_width: bool = False) -> bool: users expect. display.max_columns remains in effect. GH3541, GH3573 """ - width, height = console.get_console_size() max_columns = get_option("display.max_columns") nb_columns = len(self.columns) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fcd160ed8d9a7..f88f37fac7157 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9165,7 +9165,6 @@ def truncate( 2016-01-10 23:59:58 1 2016-01-10 23:59:59 1 """ - if axis is None: axis = self._stat_axis_number axis = self._get_axis_number(axis) @@ -9391,9 +9390,9 @@ def tz_localize( nonexistent, timedelta ): raise ValueError( - "The nonexistent argument must be one of 'raise'," - " 'NaT', 'shift_forward', 'shift_backward' or" - " a timedelta object" + "The nonexistent argument must be one of 'raise', " + "'NaT', 'shift_forward', 'shift_backward' or " + "a timedelta object" ) axis = self._get_axis_number(axis) diff --git a/pandas/core/series.py b/pandas/core/series.py index 965736a097c21..3eabb70581827 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -197,9 +197,9 @@ def __init__( if is_empty_data(data) and dtype is None: # gh-17261 warnings.warn( - "The default dtype for empty Series will be 'object' instead" - " of 'float64' in a future version. Specify a dtype explicitly" - " to silence this warning.", + "The default dtype for empty Series will be 'object' instead " + "of 'float64' in a future version. Specify a dtype explicitly " + "to silence this warning.", DeprecationWarning, stacklevel=2, ) @@ -257,14 +257,13 @@ def __init__( raise AssertionError( "Cannot pass both SingleBlockManager " "`data` argument and a different " - "`index` argument. `copy` must " - "be False." + "`index` argument. `copy` must be False." ) elif is_extension_array_dtype(data): pass elif isinstance(data, (set, frozenset)): - raise TypeError(f"{repr(type(data).__name__)} type is unordered") + raise TypeError(f"'{type(data).__name__}' type is unordered") elif isinstance(data, ABCSparseArray): # handle sparse passed here (and force conversion) data = data.to_dense() @@ -3721,7 +3720,6 @@ def _reduce( If we have an ndarray as a value, then simply perform the operation, otherwise delegate to the object. """ - delegate = self._values if axis is not None: diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index e9e5959454807..f2818a0b92e6b 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -838,19 +838,16 @@ def coerce(values): ) try: values = to_datetime(values, format="%Y%m%d", errors=errors, utc=tz) - except (TypeError, ValueError) as e: - raise ValueError("cannot assemble the datetimes: {error}".format(error=e)) + except (TypeError, ValueError) as err: + raise ValueError(f"cannot assemble the datetimes: {err}") for u in ["h", "m", "s", "ms", "us", "ns"]: value = unit_rev.get(u) if value is not None and value in arg: try: values += to_timedelta(coerce(arg[value]), unit=u, errors=errors) - except (TypeError, ValueError) as e: - raise ValueError( - "cannot assemble the datetimes [{value}]: " - "{error}".format(value=value, error=e) - ) + except (TypeError, ValueError) as err: + raise ValueError(f"cannot assemble the datetimes [{value}]: {err}") return values diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 8337318ac6bcc..baecba7e78384 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -231,8 +231,7 @@ def _apply(self, func, **kwargs): cfunc = getattr(window_aggregations, func, None) if cfunc is None: raise ValueError( - "we do not support this function " - f"in window_aggregations.{func}" + f"we do not support this function in window_aggregations.{func}" ) def func(arg):