geopandas / pyogrio

Vectorized vector I/O using OGR
https://pyogrio.readthedocs.io
MIT License
259 stars 22 forks source link

BUG: error when writing a dataframe with a date column and non-consecutive index values #324

Closed theroggy closed 8 months ago

theroggy commented 8 months ago

I updated a test as a reproducable test case:

def test_read_datetime_tz(test_datetime_tz, tmp_path):
    df = read_dataframe(test_datetime_tz)
    # Make the index non-consecutive to test this case as well
    df = df.set_index(np.array([0, 2]))
    raw_expected = ["2020-01-01T09:00:00.123-05:00", "2020-01-01T10:00:00-05:00"]

    if PANDAS_GE_20:
        expected = pd.to_datetime(raw_expected, format="ISO8601").as_unit("ms")
    else:
        expected = pd.to_datetime(raw_expected)
    expected = pd.Series(expected, name="datetime_col", index=non_consecutive_indices)
    assert_series_equal(df.datetime_col, expected, check_index=False)
    # test write and read round trips
    fpath = tmp_path / "test.gpkg"
    write_dataframe(df, fpath)
    df_read = read_dataframe(fpath)
    assert_series_equal(df_read.datetime_col, expected)