Skip to content
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
8 changes: 4 additions & 4 deletions tests/io/test_postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_non_standard_column_names(self, example_positionfixes, conn_postgis):
try:
pfs.as_positionfixes.to_postgis(table, conn_string)
with pytest.warns(UserWarning):
pfs_db = ti.io.read_positionfixes_postgis(sql, conn, geom_col, index_col="id", **rename_dict)
pfs_db = ti.io.read_positionfixes_postgis(sql, conn, geom_col, index_col="id", read_gpd_kws=rename_dict)
assert_geodataframe_equal(example_positionfixes, pfs_db)
finally:
del_table(conn, table)
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_non_standard_column_names(self, example_triplegs, conn_postgis):
try:
tpls.as_triplegs.to_postgis(table, conn_string)
with pytest.warns(UserWarning):
tpls_db = ti.io.read_triplegs_postgis(sql, conn, geom_col, index_col="id", **rename_dict)
tpls_db = ti.io.read_triplegs_postgis(sql, conn, geom_col, index_col="id", read_gpd_kws=rename_dict)
assert_geodataframe_equal(example_triplegs, tpls_db)
finally:
del_table(conn, table)
Expand Down Expand Up @@ -571,7 +571,7 @@ def test_non_standard_column_names(self, example_locations, conn_postgis):
try:
locs.as_locations.to_postgis(table, conn_string)
with pytest.warns(UserWarning):
tpls_db = ti.io.read_locations_postgis(sql, conn, geom_col, index_col="id", **rename_dict)
tpls_db = ti.io.read_locations_postgis(sql, conn, geom_col, index_col="id", read_gpd_kws=rename_dict)
assert_geodataframe_equal(example_locations, tpls_db)
finally:
del_table(conn, table)
Expand Down Expand Up @@ -624,7 +624,7 @@ def test_non_standard_column_names(self, example_trips, conn_postgis):
try:
trips.as_trips.to_postgis(table, create_engine(conn_string))
with pytest.warns(UserWarning):
tpls_db = ti.io.read_trips_postgis(sql, conn, index_col="id", **rename_dict)
tpls_db = ti.io.read_trips_postgis(sql, conn, index_col="id", read_gpd_kws=rename_dict)
assert_frame_equal(example_trips, tpls_db)
finally:
del_table(conn, table)
Expand Down
61 changes: 33 additions & 28 deletions trackintel/io/postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def read_positionfixes_postgis(
parse_dates=None,
params=None,
chunksize=None,
**kwargs
read_gpd_kws=None,
Comment thread
bifbof marked this conversation as resolved.
):
"""Reads positionfixes from a PostGIS database.

Expand Down Expand Up @@ -92,7 +92,7 @@ def read_positionfixes_postgis(
If specified, return an iterator where chunksize is the number
of rows to include in each chunk.

**kwargs
read_gpd_kws : dict, default None
Further keyword arguments as available in trackintels trackintel.io.read_positionfixes_gpd().
Especially useful to rename column names from the SQL table to trackintel conform column names.
See second example how to use it in code.
Comment thread
bifbof marked this conversation as resolved.
Expand All @@ -106,7 +106,8 @@ def read_positionfixes_postgis(
--------
>>> pfs = ti.io.read_positionfixes_postgis("SELECT * FROM positionfixes", con, geom_col="geom")
>>> pfs = ti.io.read_positionfixes_postgis("SELECT * FROM positionfixes", con, geom_col="geom",
... index_col="id", user_id="USER", tracked_at="time")
... index_col="id",
read_gpd_kws={"user_id"="USER", "tracked_at": "time"})
"""
pfs = gpd.GeoDataFrame.from_postgis(
sql,
Expand All @@ -119,7 +120,7 @@ def read_positionfixes_postgis(
params=params,
chunksize=chunksize,
)
return ti.io.read_positionfixes_gpd(pfs, **kwargs)
return ti.io.read_positionfixes_gpd(pfs, **(read_gpd_kws or {}))


@_handle_con_string
Expand Down Expand Up @@ -149,7 +150,7 @@ def read_triplegs_postgis(
parse_dates=None,
params=None,
chunksize=None,
**kwargs
read_gpd_kws=None,
):
"""Reads triplegs from a PostGIS database.

Expand Down Expand Up @@ -191,7 +192,7 @@ def read_triplegs_postgis(
If specified, return an iterator where chunksize is the number
of rows to include in each chunk.

**kwargs
read_gpd_kws : dict, default None
Further keyword arguments as available in trackintels trackintel.io.read_triplegs_gpd().
Especially useful to rename column names from the SQL table to trackintel conform column names.
See second example how to use it in code.
Expand All @@ -205,7 +206,7 @@ def read_triplegs_postgis(
--------
>>> tpls = ti.io.read_triplegs_postgis("SELECT * FROM triplegs", con, geom_col="geom")
>>> tpls = ti.io.read_triplegs_postgis("SELECT * FROM triplegs", con, geom_col="geom", index_col="id",
... started_at="start_time", finished_at="end_time", user_id="USER")
... read_gpd_kws={"user_id": "USER"})
"""
tpls = gpd.GeoDataFrame.from_postgis(
sql,
Expand All @@ -218,7 +219,7 @@ def read_triplegs_postgis(
params=params,
chunksize=chunksize,
)
return ti.io.read_triplegs_gpd(tpls, **kwargs)
return ti.io.read_triplegs_gpd(tpls, **(read_gpd_kws or {}))


@_handle_con_string
Expand Down Expand Up @@ -248,7 +249,7 @@ def read_staypoints_postgis(
parse_dates=None,
params=None,
chunksize=None,
**kwargs
read_gpd_kws=None,
):
"""Read staypoints from a PostGIS database.

Expand Down Expand Up @@ -290,7 +291,7 @@ def read_staypoints_postgis(
If specified, return an iterator where chunksize is the number
of rows to include in each chunk.

**kwargs
read_gpd_kws : dict, default None
Further keyword arguments as available in trackintels trackintel.io.read_staypoints_gpd().
Especially useful to rename column names from the SQL table to trackintel conform column names.
See second example how to use it in code.
Expand All @@ -305,7 +306,7 @@ def read_staypoints_postgis(
--------
>>> sp = ti.io.read_staypoints_postgis("SELECT * FROM staypoints", con, geom_col="geom")
>>> sp = ti.io.read_staypoints_postgis("SELECT * FROM staypoints", con, geom_col="geom", index_col="id",
... started_at="start_time", finished_at="end_time", user_id="USER")
... read_gpd_kws={"user_id": "USER"})
"""
sp = gpd.GeoDataFrame.from_postgis(
sql,
Expand All @@ -319,7 +320,7 @@ def read_staypoints_postgis(
chunksize=chunksize,
)

return ti.io.read_staypoints_gpd(sp, **kwargs)
return ti.io.read_staypoints_gpd(sp, **(read_gpd_kws or {}))


@_handle_con_string
Expand Down Expand Up @@ -349,7 +350,8 @@ def read_locations_postgis(
parse_dates=None,
params=None,
chunksize=None,
**kwargs
extent=None,
read_gpd_kws=None,
):
"""Reads locations from a PostGIS database.

Expand Down Expand Up @@ -391,7 +393,10 @@ def read_locations_postgis(
If specified, return an iterator where chunksize is the number
of rows to include in each chunk.

**kwargs
extent : string, default None
If specified read the extent column as geometry column.

read_gpd_kws : dict, default None
Further keyword arguments as available in trackintels trackintel.io.read_locations_gpd().
Especially useful to rename column names from the SQL table to trackintel conform column names.
See second example how to use it in code.
Expand All @@ -405,7 +410,7 @@ def read_locations_postgis(
--------
>>> locs = ti.io.read_locations_postgis("SELECT * FROM locations", con, center="center")
>>> locs = ti.io.read_locations_postgis("SELECT * FROM locations", con, center="geom", index_col="id",
... user_id="USER", extent="extent")
... extent="extent, read_gpd_kws={"user_id": "USER"})
)
"""
locs = gpd.GeoDataFrame.from_postgis(
Expand All @@ -419,10 +424,10 @@ def read_locations_postgis(
params=params,
chunksize=chunksize,
)
if "extent" in kwargs:
locs[kwargs["extent"]] = gpd.GeoSeries.from_wkb(locs[kwargs["extent"]])
if extent is not None:
locs[extent] = gpd.GeoSeries.from_wkb(locs[extent])

return ti.io.read_locations_gpd(locs, center=center, **kwargs)
return ti.io.read_locations_gpd(locs, center=center, **(read_gpd_kws or {}))


@_handle_con_string
Expand Down Expand Up @@ -466,7 +471,7 @@ def read_trips_postgis(
parse_dates=None,
params=None,
chunksize=None,
**kwargs
read_gpd_kws=None,
):
"""Read trips from a PostGIS database.

Expand Down Expand Up @@ -508,7 +513,7 @@ def read_trips_postgis(
If specified, return an iterator where chunksize is the number
of rows to include in each chunk.

**kwargs
read_gpd_kws : dict, default None
Further keyword arguments as available in trackintels trackintel.io.read_trips_gpd().
Especially useful to rename column names from the SQL table to trackintel conform column names.
See second example how to use it in code.
Expand All @@ -523,8 +528,8 @@ def read_trips_postgis(
--------
>>> trips = ti.io.read_trips_postgis("SELECT * FROM trips", con)
>>> trips = ti.io.read_trips_postgis("SELECT * FROM trips", con, geom_col="geom", index_col="id",
... started_at="start_time", finished_at="end_time", user_id="USER",
... origin_staypoint_id="ORIGIN", destination_staypoint_id="DEST")
... read_gpd_kws={"user_id": "USER", "origin_staypoint_id": "ORIGIN",
"destination_staypoint_id": "DEST"})

"""
if geom_col is None:
Expand All @@ -550,7 +555,7 @@ def read_trips_postgis(
chunksize=chunksize,
)

return ti.io.read_trips_gpd(trips, **kwargs)
return ti.io.read_trips_gpd(trips, **(read_gpd_kws or {}))


@_handle_con_string
Expand Down Expand Up @@ -592,7 +597,7 @@ def read_tours_postgis(
parse_dates=None,
params=None,
chunksize=None,
**kwargs
read_gpd_kws=None,
):
"""Read tours from a PostGIS database.

Expand Down Expand Up @@ -634,7 +639,7 @@ def read_tours_postgis(
If specified, return an iterator where chunksize is the number
of rows to include in each chunk.

**kwargs
read_gpd_kws : dict, default None
Further keyword arguments as available in trackintels trackintel.io.read_tours_gpd().
Especially useful to rename column names from the SQL table to trackintel conform column names.
See second example how to use it in code.
Expand All @@ -647,8 +652,8 @@ def read_tours_postgis(
Examples
--------
>>> tours = ti.io.read_tours_postgis("SELECT * FROM tours", con)
>>> tours = ti.io.read_tours_postgis("SELECT * FROM tours", con, index_col="id", started_at="start_time",
... finished_at="end_time", user_id="USER")
>>> tours = ti.io.read_tours_postgis("SELECT * FROM tours", con, index_col="id",
read_gpd_kws={"user_id": "USER"})
"""
if geom_col is None:
tours = pd.read_sql(
Expand All @@ -673,7 +678,7 @@ def read_tours_postgis(
chunksize=chunksize,
)

return ti.io.read_tours_gpd(tours, **kwargs)
return ti.io.read_tours_gpd(tours, **(read_gpd_kws or {}))


@_handle_con_string
Expand Down