Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Fix error in write_dataframe if input has a date column and non-consecutive index values #325

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 0.7.3 (???)

### Bug fixes

- Fix error in `write_dataframe` if input has a date column and
non-consecutive index values (#325).

## 0.7.2 (2023-10-30)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion pyogrio/geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def write_dataframe(
# https://gdal.org/development/rfc/rfc56_millisecond_precision.html#core-changes
# Convert each row offset to a signed multiple of 15m and add to GMT value
gdal_offset_representation = tz_offset // pd.Timedelta("15m") + 100
gdal_tz_offsets[name] = gdal_offset_representation
gdal_tz_offsets[name] = gdal_offset_representation.values
else:
values = col.values
if isinstance(values, pd.api.extensions.ExtensionArray):
Expand Down
5 changes: 4 additions & 1 deletion pyogrio/tests/test_geopandas_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,17 @@ def test_read_datetime(test_fgdb_vsi, use_arrow):

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. Added for issue
# https://github.com/geopandas/pyogrio/issues/324
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")
assert_series_equal(df.datetime_col, expected)
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)
Expand Down