From 17a9f35992ee71e0e5e98a0761a7d7c817312075 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 7 Oct 2021 14:40:22 -0700 Subject: [PATCH 1/2] CLN: unnecessary warning-catching --- pandas/core/arrays/datetimes.py | 18 +++++++----------- pandas/core/frame.py | 10 +++++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index d9f9c07a4f645..eb7638df301f7 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -621,17 +621,13 @@ def __iter__(self): chunksize = 10000 chunks = (length // chunksize) + 1 - with warnings.catch_warnings(): - # filter out warnings about Timestamp.freq - warnings.filterwarnings("ignore", category=FutureWarning) - - for i in range(chunks): - start_i = i * chunksize - end_i = min((i + 1) * chunksize, length) - converted = ints_to_pydatetime( - data[start_i:end_i], tz=self.tz, freq=self.freq, box="timestamp" - ) - yield from converted + for i in range(chunks): + start_i = i * chunksize + end_i = min((i + 1) * chunksize, length) + converted = ints_to_pydatetime( + data[start_i:end_i], tz=self.tz, freq=self.freq, box="timestamp" + ) + yield from converted def astype(self, dtype, copy: bool = True): # We handle diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 88238ac42ecff..76a00071c8adc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9360,17 +9360,17 @@ def round( """ from pandas.core.reshape.concat import concat - def _dict_round(df, decimals): + def _dict_round(df: DataFrame, decimals): for col, vals in df.items(): try: yield _series_round(vals, decimals[col]) except KeyError: yield vals - def _series_round(s, decimals): - if is_integer_dtype(s) or is_float_dtype(s): - return s.round(decimals) - return s + def _series_round(ser: Series, decimals: int): + if is_integer_dtype(ser.dtype) or is_float_dtype(ser.dtype): + return ser.round(decimals) + return ser nv.validate_round(args, kwargs) From 42cd7ad0cb89ecd90b7c04c53294da24cae8e50b Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 7 Oct 2021 19:41:58 -0700 Subject: [PATCH 2/2] avoid warnings at import time --- pandas/tests/indexes/numeric/test_astype.py | 6 +++--- pandas/tests/indexes/numeric/test_indexing.py | 8 +++++--- pandas/tests/indexes/numeric/test_join.py | 4 ++-- pandas/tests/indexes/numeric/test_numeric.py | 8 +++++--- pandas/tests/indexes/numeric/test_setops.py | 4 ++-- pandas/tests/indexes/period/methods/test_astype.py | 6 ++++-- pandas/tests/indexes/ranges/test_join.py | 2 +- pandas/tests/indexes/ranges/test_range.py | 4 ++-- pandas/tests/indexes/ranges/test_setops.py | 4 ++-- pandas/tests/indexes/timedeltas/test_timedelta.py | 2 +- pandas/tests/indexing/test_partial.py | 6 +++--- 11 files changed, 30 insertions(+), 24 deletions(-) diff --git a/pandas/tests/indexes/numeric/test_astype.py b/pandas/tests/indexes/numeric/test_astype.py index bda66856fb57a..89f26e953400d 100644 --- a/pandas/tests/indexes/numeric/test_astype.py +++ b/pandas/tests/indexes/numeric/test_astype.py @@ -5,12 +5,12 @@ from pandas.core.dtypes.common import pandas_dtype -from pandas import ( +from pandas import Index +import pandas._testing as tm +from pandas.core.indexes.api import ( Float64Index, - Index, Int64Index, ) -import pandas._testing as tm class TestAstype: diff --git a/pandas/tests/indexes/numeric/test_indexing.py b/pandas/tests/indexes/numeric/test_indexing.py index be05d5d8a9cae..cb861aaab80f8 100644 --- a/pandas/tests/indexes/numeric/test_indexing.py +++ b/pandas/tests/indexes/numeric/test_indexing.py @@ -2,15 +2,17 @@ import pytest from pandas import ( - Float64Index, Index, - Int64Index, RangeIndex, Series, Timestamp, - UInt64Index, ) import pandas._testing as tm +from pandas.core.indexes.api import ( + Float64Index, + Int64Index, + UInt64Index, +) @pytest.fixture diff --git a/pandas/tests/indexes/numeric/test_join.py b/pandas/tests/indexes/numeric/test_join.py index 43d731f8c3142..2a47289b65aad 100644 --- a/pandas/tests/indexes/numeric/test_join.py +++ b/pandas/tests/indexes/numeric/test_join.py @@ -1,12 +1,12 @@ import numpy as np import pytest -from pandas import ( +import pandas._testing as tm +from pandas.core.indexes.api import ( Index, Int64Index, UInt64Index, ) -import pandas._testing as tm class TestJoinInt64Index: diff --git a/pandas/tests/indexes/numeric/test_numeric.py b/pandas/tests/indexes/numeric/test_numeric.py index 6d35568b69fac..ec451ac13ec44 100644 --- a/pandas/tests/indexes/numeric/test_numeric.py +++ b/pandas/tests/indexes/numeric/test_numeric.py @@ -5,14 +5,16 @@ import pandas as pd from pandas import ( - Float64Index, Index, - Int64Index, NumericIndex, Series, - UInt64Index, ) import pandas._testing as tm +from pandas.core.indexes.api import ( + Float64Index, + Int64Index, + UInt64Index, +) from pandas.tests.indexes.common import NumericBase diff --git a/pandas/tests/indexes/numeric/test_setops.py b/pandas/tests/indexes/numeric/test_setops.py index 5a7db9858dbad..4045cc0b91313 100644 --- a/pandas/tests/indexes/numeric/test_setops.py +++ b/pandas/tests/indexes/numeric/test_setops.py @@ -6,14 +6,14 @@ import numpy as np import pytest -from pandas import ( +import pandas._testing as tm +from pandas.core.indexes.api import ( Float64Index, Index, Int64Index, RangeIndex, UInt64Index, ) -import pandas._testing as tm @pytest.fixture diff --git a/pandas/tests/indexes/period/methods/test_astype.py b/pandas/tests/indexes/period/methods/test_astype.py index 74f627478a29c..e2340a2db02f7 100644 --- a/pandas/tests/indexes/period/methods/test_astype.py +++ b/pandas/tests/indexes/period/methods/test_astype.py @@ -5,15 +5,17 @@ CategoricalIndex, DatetimeIndex, Index, - Int64Index, NaT, Period, PeriodIndex, Timedelta, - UInt64Index, period_range, ) import pandas._testing as tm +from pandas.core.indexes.api import ( + Int64Index, + UInt64Index, +) class TestPeriodIndexAsType: diff --git a/pandas/tests/indexes/ranges/test_join.py b/pandas/tests/indexes/ranges/test_join.py index 6668a7c6a3d02..353605da91f94 100644 --- a/pandas/tests/indexes/ranges/test_join.py +++ b/pandas/tests/indexes/ranges/test_join.py @@ -2,10 +2,10 @@ from pandas import ( Index, - Int64Index, RangeIndex, ) import pandas._testing as tm +from pandas.core.indexes.api import Int64Index class TestJoin: diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py index 1b98f3c8194b5..7dcdb627b9abb 100644 --- a/pandas/tests/indexes/ranges/test_range.py +++ b/pandas/tests/indexes/ranges/test_range.py @@ -4,13 +4,13 @@ from pandas.core.dtypes.common import ensure_platform_int import pandas as pd -from pandas import ( +import pandas._testing as tm +from pandas.core.indexes.api import ( Float64Index, Index, Int64Index, RangeIndex, ) -import pandas._testing as tm from pandas.tests.indexes.common import NumericBase # aliases to make some tests easier to read diff --git a/pandas/tests/indexes/ranges/test_setops.py b/pandas/tests/indexes/ranges/test_setops.py index ba938f82e9d89..6dc47b7fef5ac 100644 --- a/pandas/tests/indexes/ranges/test_setops.py +++ b/pandas/tests/indexes/ranges/test_setops.py @@ -6,13 +6,13 @@ import numpy as np import pytest -from pandas import ( +import pandas._testing as tm +from pandas.core.indexes.api import ( Index, Int64Index, RangeIndex, UInt64Index, ) -import pandas._testing as tm class TestRangeIndexSetOps: diff --git a/pandas/tests/indexes/timedeltas/test_timedelta.py b/pandas/tests/indexes/timedeltas/test_timedelta.py index 9672929ecc06b..8ceef8186e4ea 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta.py @@ -6,7 +6,6 @@ import pandas as pd from pandas import ( Index, - Int64Index, NaT, Series, Timedelta, @@ -14,6 +13,7 @@ timedelta_range, ) import pandas._testing as tm +from pandas.core.indexes.api import Int64Index from pandas.tests.indexes.datetimelike import DatetimeLike randn = np.random.randn diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index 172301a2fde84..7b2713ad274c6 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -540,9 +540,9 @@ def test_partial_set_empty_frame_empty_consistencies(self): date_range(start="2000", periods=20, freq="D"), ["2000-01-04", "2000-01-08", "2000-01-12"], [ - Timestamp("2000-01-04", freq="D"), - Timestamp("2000-01-08", freq="D"), - Timestamp("2000-01-12", freq="D"), + Timestamp("2000-01-04"), + Timestamp("2000-01-08"), + Timestamp("2000-01-12"), ], ), (