diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 6cce1137e707b..64f5d97f588c5 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -610,8 +610,6 @@ def makeCustomIndex( for i in range(nlevels): def keyfunc(x): - import re - numeric_tuple = re.sub(r"[^\d_]_?", "", x).split("_") return [int(num) for num in numeric_tuple] diff --git a/pandas/_testing/contexts.py b/pandas/_testing/contexts.py index ee94c1d3aae0c..e5f716c62eca7 100644 --- a/pandas/_testing/contexts.py +++ b/pandas/_testing/contexts.py @@ -62,7 +62,6 @@ def set_timezone(tz: str) -> Generator[None, None, None]: ... 'EST' """ - import os import time def setTZ(tz) -> None: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d26a11eae9f7f..8398abc9cc78a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9045,8 +9045,6 @@ def compare( keep_equal: bool_t = False, result_names: Suffixes = ("self", "other"), ): - from pandas.core.reshape.concat import concat - if type(self) is not type(other): cls_self, cls_other = type(self).__name__, type(other).__name__ raise TypeError( diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 591fa25bd36d1..a7d1da69e2729 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -741,7 +741,6 @@ def pandasSQL_builder(con, schema: str | None = None) -> SQLDatabase | SQLiteDat provided parameters. """ import sqlite3 - import warnings if isinstance(con, sqlite3.Connection) or con is None: return SQLiteDatabase(con) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index dea5dbd33bbdf..27603f7d987d2 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1655,8 +1655,6 @@ def _start_base(self): return self.bottom def _make_plot(self) -> None: - import matplotlib as mpl - colors = self._get_colors() ncolors = len(colors) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index e3b7ad8f78750..9659b4aa5f45c 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -393,8 +393,6 @@ def test_groupby_grouper(self, df): def test_groupby_dict_mapping(self): # GH #679 - from pandas import Series - s = Series({"T1": 5}) result = s.groupby({"T1": "T2"}).agg(sum) expected = s.groupby(["T2"]).agg(sum) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 0068a0a0ded67..26eb7532adfa4 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -953,11 +953,7 @@ def test_loc_coercion(self): def test_loc_coercion2(self): # GH#12045 - import datetime - - df = DataFrame( - {"date": [datetime.datetime(2012, 1, 1), datetime.datetime(1012, 1, 2)]} - ) + df = DataFrame({"date": [datetime(2012, 1, 1), datetime(1012, 1, 2)]}) expected = df.dtypes result = df.iloc[[0]] diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index ee2a8f518cd56..bff4c98fe2842 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -882,10 +882,7 @@ def test_read_from_file_url(self, read_ext, datapath): tm.assert_frame_equal(url_table, local_table) def test_read_from_pathlib_path(self, read_ext): - # GH12655 - from pathlib import Path - str_path = "test1" + read_ext expected = pd.read_excel(str_path, sheet_name="Sheet1", index_col=0) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index f870ef25991df..640c686bb56ca 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -5,6 +5,7 @@ from datetime import ( datetime, time, + timedelta, ) from io import StringIO import itertools @@ -994,12 +995,10 @@ def test_truncate_with_different_dtypes(self): # when truncated the dtypes of the splits can differ # 11594 - import datetime - s = Series( - [datetime.datetime(2012, 1, 1)] * 10 - + [datetime.datetime(1012, 1, 2)] - + [datetime.datetime(2012, 1, 3)] * 10 + [datetime(2012, 1, 1)] * 10 + + [datetime(1012, 1, 2)] + + [datetime(2012, 1, 3)] * 10 ) with option_context("display.max_rows", 8): @@ -1250,8 +1249,6 @@ def test_long_series(self): dtype="int64", ) - import re - str_rep = str(s) nmatches = len(re.findall("dtype", str_rep)) assert nmatches == 1 @@ -2445,12 +2442,6 @@ def test_datetimeindex_highprecision(self, start_date): assert start_date in result def test_timedelta64(self): - - from datetime import ( - datetime, - timedelta, - ) - Series(np.array([1100, 20], dtype="timedelta64[ns]")).to_string() s = Series(date_range("2012-1-1", periods=3, freq="D")) diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index 231228ef6c0af..986c0039715a6 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -866,7 +866,7 @@ def test_with_large_max_level(self): def test_deprecated_import(self): with tm.assert_produces_warning(FutureWarning): - from pandas.io.json import json_normalize + from pandas.io.json import json_normalize # pylint: disable=reimported recs = [{"a": 1, "b": 2, "c": 3}, {"a": 4, "b": 5, "c": 6}] json_normalize(recs) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 8888e2687621d..7d60ebabfbe01 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -890,8 +890,6 @@ def test_idxmax(self): allna = string_series * np.nan assert isna(allna.idxmax()) - from pandas import date_range - s = Series(date_range("20130102", periods=6)) result = s.idxmax() assert result == 5 diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index 93d212d0a581d..f16358813488e 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -22,8 +22,6 @@ class TestDatetimeConcat: def test_concat_datetime64_block(self): - from pandas.core.indexes.datetimes import date_range - rng = date_range("1/1/2000", periods=10) df = DataFrame({"time": rng}) diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 1e929cd43842b..689c8ba845a6c 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -632,12 +632,6 @@ def test_strftime_all_nat(self, data): tm.assert_series_equal(result, expected) def test_valid_dt_with_missing_values(self): - - from datetime import ( - date, - time, - ) - # GH 8689 ser = Series(date_range("20130101", periods=5, freq="D")) ser.iloc[2] = pd.NaT diff --git a/pandas/tests/tseries/offsets/test_custom_business_month.py b/pandas/tests/tseries/offsets/test_custom_business_month.py index 36c690e89256d..bc9f7f3f511b8 100644 --- a/pandas/tests/tseries/offsets/test_custom_business_month.py +++ b/pandas/tests/tseries/offsets/test_custom_business_month.py @@ -400,8 +400,6 @@ def test_holidays(self): @pytest.mark.filterwarnings("ignore:Non:pandas.errors.PerformanceWarning") def test_datetimeindex(self): - from pandas.tseries.holiday import USFederalHolidayCalendar - hcal = USFederalHolidayCalendar() freq = CBMonthEnd(calendar=hcal) diff --git a/pyproject.toml b/pyproject.toml index 71b1f44dbff6f..b436b29c03c84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -153,7 +153,6 @@ disable = [ "raise-missing-from", "redefined-builtin", "redefined-outer-name", - "reimported", "self-assigning-variable", "self-cls-assignment", "signature-differs",