From 6e83c4b8114539701c17b7ced0973ac32356eaf8 Mon Sep 17 00:00:00 2001 From: Mathias <99316631+MCRE-BE@users.noreply.github.com> Date: Thu, 17 Oct 2024 07:15:04 +0200 Subject: [PATCH 1/2] [TST] First try of pyarrow_dtype as datetime index --- pandas/tests/io/parser/test_parse_dates.py | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 532fcc5cd880c..885abea3213ce 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -848,6 +848,34 @@ def test_parse_dates_arrow_engine(all_parsers): tm.assert_frame_equal(result, expected) +def test_parse_dates_arrow_dtype_as_index(all_parsers): + # GH#57930 + parser = all_parsers + data = """a,b +2000-01-01 00:00:00,1 +2000-01-01 00:00:01,1""" + + result = parser.read_csv( + StringIO(data), + parse_dates=["a"], + index_col="a", + dtype_backend="pyarrow", + ) + expected = pd.Series( + [1, 1], + name="b", + dtype="int64[pyarrow]", + index=pd.Index( + [ + Timestamp("2000-01-01 00:00:00"), + Timestamp("2000-01-01 00:00:01"), + ], + name="a", + ), + ).to_frame() + tm.assert_frame_equal(result, expected) + + @xfail_pyarrow # object dtype index def test_from_csv_with_mixed_offsets(all_parsers): parser = all_parsers From 19a1733435948c8acb7abd1629bacf7de73ff923 Mon Sep 17 00:00:00 2001 From: Mathias <99316631+MCRE-BE@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:40:38 +0200 Subject: [PATCH 2/2] [FIX] Pre-commit warnings because using pd.XXX --- pandas/tests/io/parser/test_parse_dates.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 885abea3213ce..ff4a40f96889b 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -13,9 +13,8 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - import pandas as pd +import pandas._testing as tm from pandas import ( DataFrame, DatetimeIndex, @@ -24,10 +23,9 @@ Series, Timestamp, ) -import pandas._testing as tm +from pandas._config import using_string_dtype from pandas.core.indexes.datetimes import date_range from pandas.core.tools.datetimes import start_caching_at - from pandas.io.parsers import read_csv pytestmark = pytest.mark.filterwarnings( @@ -861,11 +859,11 @@ def test_parse_dates_arrow_dtype_as_index(all_parsers): index_col="a", dtype_backend="pyarrow", ) - expected = pd.Series( + expected = Series( [1, 1], name="b", dtype="int64[pyarrow]", - index=pd.Index( + index=Index( [ Timestamp("2000-01-01 00:00:00"), Timestamp("2000-01-01 00:00:01"),