From ab64e59c6a4bf8d2a5f803adecc100074e311ca5 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Mon, 24 Jul 2023 20:31:03 +0200 Subject: [PATCH 1/3] TST: add a test on mixed offsets for read_csv --- pandas/tests/frame/methods/test_to_csv.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/frame/methods/test_to_csv.py b/pandas/tests/frame/methods/test_to_csv.py index ee9c4f05991a0..68f26bda818f7 100644 --- a/pandas/tests/frame/methods/test_to_csv.py +++ b/pandas/tests/frame/methods/test_to_csv.py @@ -1310,3 +1310,16 @@ def test_to_csv_categorical_and_interval(self): expected_rows = [",a", '0,"[2020-01-01, 2020-01-02]"'] expected = tm.convert_rows_list_to_csv_str(expected_rows) assert result == expected + + def test_from_csv_with_mixed_offsets(self): + content = "a\n2020-01-01T00:00:00+01:00\n2020-01-01T00:00:00+00:00" + result = read_csv(StringIO(content), parse_dates=["a"])["a"] + expected = Series( + [ + Timestamp("2020-01-01 00:00:00+01:00"), + Timestamp("2020-01-01 00:00:00+00:00"), + ], + name="a", + index=[0, 1], + ) + tm.assert_series_equal(result, expected) From 6c74295aea8ed8c604356f382581e7437fb76701 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 25 Jul 2023 09:37:46 +0200 Subject: [PATCH 2/3] change the location of the test --- pandas/tests/frame/methods/test_to_csv.py | 13 ------------- pandas/tests/io/parser/test_parse_dates.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pandas/tests/frame/methods/test_to_csv.py b/pandas/tests/frame/methods/test_to_csv.py index 68f26bda818f7..ee9c4f05991a0 100644 --- a/pandas/tests/frame/methods/test_to_csv.py +++ b/pandas/tests/frame/methods/test_to_csv.py @@ -1310,16 +1310,3 @@ def test_to_csv_categorical_and_interval(self): expected_rows = [",a", '0,"[2020-01-01, 2020-01-02]"'] expected = tm.convert_rows_list_to_csv_str(expected_rows) assert result == expected - - def test_from_csv_with_mixed_offsets(self): - content = "a\n2020-01-01T00:00:00+01:00\n2020-01-01T00:00:00+00:00" - result = read_csv(StringIO(content), parse_dates=["a"])["a"] - expected = Series( - [ - Timestamp("2020-01-01 00:00:00+01:00"), - Timestamp("2020-01-01 00:00:00+00:00"), - ], - name="a", - index=[0, 1], - ) - tm.assert_series_equal(result, expected) diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 571e09bb5e9dd..fd2a389b05b28 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -2237,3 +2237,17 @@ def test_parse_dates_arrow_engine(all_parsers): } ) tm.assert_frame_equal(result, expected) + + +def test_from_csv_with_mixed_offsets(): + content = "a\n2020-01-01T00:00:00+01:00\n2020-01-01T00:00:00+00:00" + result = read_csv(StringIO(content), parse_dates=["a"])["a"] + expected = Series( + [ + Timestamp("2020-01-01 00:00:00+01:00"), + Timestamp("2020-01-01 00:00:00+00:00"), + ], + name="a", + index=[0, 1], + ) + tm.assert_series_equal(result, expected) From a1b274a5814a6a07e2534323f5a579d4a6d5cfc0 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 25 Jul 2023 10:02:18 +0200 Subject: [PATCH 3/3] add parser to the test --- pandas/tests/io/parser/test_parse_dates.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index fd2a389b05b28..d4d8d909adef6 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -2239,9 +2239,11 @@ def test_parse_dates_arrow_engine(all_parsers): tm.assert_frame_equal(result, expected) -def test_from_csv_with_mixed_offsets(): - content = "a\n2020-01-01T00:00:00+01:00\n2020-01-01T00:00:00+00:00" - result = read_csv(StringIO(content), parse_dates=["a"])["a"] +@xfail_pyarrow +def test_from_csv_with_mixed_offsets(all_parsers): + parser = all_parsers + data = "a\n2020-01-01T00:00:00+01:00\n2020-01-01T00:00:00+00:00" + result = parser.read_csv(StringIO(data), parse_dates=["a"])["a"] expected = Series( [ Timestamp("2020-01-01 00:00:00+01:00"),