Skip to content

Commit

Permalink
Upgrade deps to fix docs build; Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitan94 committed Jun 11, 2022
1 parent c159c9c commit d3a9034
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 222 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
repos:
- repo: https://github.com/mverteuil/precommit-dephell
rev: master
rev: d62e4fd01b6616a673d2305d6eb0f2bd45556996
hooks:
- id: dephell
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: stable
rev: 22.3.0
hooks:
- id: black
exclude: setup.py
223 changes: 68 additions & 155 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ to = {format = "setuppy", path = "setup.py"}

[tool.poetry]
name = "mobilitydb-sqlalchemy"
version = "0.4"
version = "0.4.1"
description = "MobilityDB extensions to SQLAlchemy"
readme = "README.rst"
license = "MIT"
Expand Down Expand Up @@ -35,27 +35,30 @@ repository = "https://github.com/adonmo/mobilitydb-sqlalchemy"
documentation = "https://mobilitydb-sqlalchemy.readthedocs.io/en/latest/"

[tool.poetry.dependencies]
python = ">=3.7.1"
python = ">=3.7.1,<4"
pandas = "^1.2.5"
sqlalchemy = "^1.3.18"
geoalchemy2 = "^0.8.4"
shapely = "^1.7.0"
movingpandas = {version = "^0.4rc1", optional = true}
sphinx = {version = "^2.3.1", optional = true}
sphinx-rtd-theme = {version = "^0.4.3", optional = true}
Jinja2 = {version = "<3.1", optional = true}
tomlkit = {version = "^0.5.8", optional = true}
pymeos = "^0.1.1"
urllib3 = "^1.26.9"

[tool.poetry.dev-dependencies]
dephell = "^0.8.3"
fissix = "^20.5.1"
pytest = "^6.0.1"
psycopg2 = "^2.8.5"
pre-commit = "^2.6.0"
black = "^19.10b0"
black = "^22.3.0"
mistune = "0.8.4"

[tool.poetry.extras]
docs = ["sphinx", "sphinx-rtd-theme", "tomlkit"]
docs = ["sphinx", "sphinx-rtd-theme", "tomlkit", "Jinja2"]

# Currently installing the optional dependency of movingpandas
# using `poetry install -E movingpandas` doesn't work
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
setup(
long_description=readme,
name='mobilitydb-sqlalchemy',
version='0.4',
version='0.4.1',
description='MobilityDB extensions to SQLAlchemy',
python_requires='>=3.7',
python_requires='<4,>=3.7.1',
project_urls={"documentation": "https://mobilitydb-sqlalchemy.readthedocs.io/en/latest/", "homepage": "https://github.com/adonmo/mobilitydb-sqlalchemy", "repository": "https://github.com/adonmo/mobilitydb-sqlalchemy"},
author='B Krishna Chaitanya',
author_email='bkchaitan94@gmail.com',
Expand All @@ -36,6 +36,6 @@
packages=['mobilitydb_sqlalchemy', 'mobilitydb_sqlalchemy.types'],
package_dir={"": "."},
package_data={},
install_requires=['geoalchemy2==0.*,>=0.8.4', 'pandas==1.*,>=1.1.0', 'pymeos==0.*,>=0.1.1', 'shapely==1.*,>=1.7.0', 'sqlalchemy==1.*,>=1.3.18'],
extras_require={"dev": ["black==19.*,>=19.10.0.b0", "dephell==0.*,>=0.8.3", "fissix==20.*,>=20.5.1", "pre-commit==2.*,>=2.6.0", "psycopg2==2.*,>=2.8.5", "pytest==6.*,>=6.0.1"], "docs": ["sphinx==2.*,>=2.3.1", "sphinx-rtd-theme==0.*,>=0.4.3", "tomlkit==0.*,>=0.5.8"], "movingpandas": ["movingpandas==0.*,>=0.4.0.rc1"]},
install_requires=['geoalchemy2==0.*,>=0.8.4', 'pandas==1.*,>=1.2.5', 'pymeos==0.*,>=0.1.1', 'shapely==1.*,>=1.7.0', 'sqlalchemy==1.*,>=1.3.18', 'urllib3==1.*,>=1.26.9'],
extras_require={"dev": ["black==22.*,>=22.3.0", "dephell==0.*,>=0.8.3", "fissix==20.*,>=20.5.1", "mistune==0.8.4", "pre-commit==2.*,>=2.6.0", "psycopg2==2.*,>=2.8.5", "pytest==6.*,>=6.0.1"], "docs": ["jinja2<3.1", "sphinx==2.*,>=2.3.1", "sphinx-rtd-theme==0.*,>=0.4.3", "tomlkit==0.*,>=0.5.8"], "movingpandas": ["movingpandas==0.*,>=0.4.0.rc1"]},
)
23 changes: 19 additions & 4 deletions tests/test_tbool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def test_simple_insert(session):
]
).set_index("t")

session.add(TemporalBools(tdata=df,))
session.add(
TemporalBools(
tdata=df,
)
)
session.commit()

sql = session.query(TemporalBools).filter(TemporalBools.id == 1)
Expand Down Expand Up @@ -49,18 +53,29 @@ def test_float_values_are_invalid(session):
).set_index("t")

with pytest.raises(StatementError):
session.add(TemporalBools(tdata=df,))
session.add(
TemporalBools(
tdata=df,
)
)
session.commit()


def test_str_values_are_invalid(session):
df = pd.DataFrame(
[
{"value": "True", "t": datetime.datetime(2018, 1, 1, 12, 0, 0)},
{"value": "False", "t": datetime.datetime(2018, 1, 1, 12, 6, 0),},
{
"value": "False",
"t": datetime.datetime(2018, 1, 1, 12, 6, 0),
},
]
).set_index("t")

with pytest.raises(StatementError):
session.add(TemporalBools(tdata=df,))
session.add(
TemporalBools(
tdata=df,
)
)
session.commit()
24 changes: 20 additions & 4 deletions tests/test_tfloat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def test_simple_insert(session):
]
).set_index("t")

session.add(TemporalFloats(tdata=df,))
session.add(
TemporalFloats(
tdata=df,
)
)
session.commit()

sql = session.query(TemporalFloats).filter(TemporalFloats.id == 1)
Expand All @@ -40,7 +44,11 @@ def test_int_values_are_valid(session):
]
).set_index("t")

session.add(TemporalFloats(tdata=df,))
session.add(
TemporalFloats(
tdata=df,
)
)
session.commit()


Expand All @@ -53,7 +61,11 @@ def test_bool_values_are_invalid(session):
).set_index("t")

with pytest.raises(StatementError):
session.add(TemporalFloats(tdata=df,))
session.add(
TemporalFloats(
tdata=df,
)
)
session.commit()


Expand All @@ -66,5 +78,9 @@ def test_str_values_are_invalid(session):
).set_index("t")

with pytest.raises(StatementError):
session.add(TemporalFloats(tdata=df,))
session.add(
TemporalFloats(
tdata=df,
)
)
session.commit()
130 changes: 107 additions & 23 deletions tests/test_tgeogpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@
def test_simple_insert(session):
df = pd.DataFrame(
[
{"geometry": Point(0, 0), "t": datetime.datetime(2012, 1, 1, 8, 0, 0),},
{"geometry": Point(2, 0), "t": datetime.datetime(2012, 1, 1, 8, 10, 0),},
{"geometry": Point(2, -1.9), "t": datetime.datetime(2012, 1, 1, 8, 15, 0),},
{
"geometry": Point(0, 0),
"t": datetime.datetime(2012, 1, 1, 8, 0, 0),
},
{
"geometry": Point(2, 0),
"t": datetime.datetime(2012, 1, 1, 8, 10, 0),
},
{
"geometry": Point(2, -1.9),
"t": datetime.datetime(2012, 1, 1, 8, 15, 0),
},
]
).set_index("t")

session.add(GeogTrips(car_id=1, trip_id=1, trip=df,))
session.add(
GeogTrips(
car_id=1,
trip_id=1,
trip=df,
)
)
session.commit()

sql = session.query(GeogTrips).filter(GeogTrips.trip_id == 1)
Expand All @@ -51,8 +66,14 @@ def test_simple_insert_with_movingpandas(session):

df = pd.DataFrame(
[
{"geometry": Point(0, 0), "t": datetime.datetime(2012, 1, 1, 8, 0, 0),},
{"geometry": Point(2, 0), "t": datetime.datetime(2012, 1, 1, 8, 10, 0),},
{
"geometry": Point(0, 0),
"t": datetime.datetime(2012, 1, 1, 8, 0, 0),
},
{
"geometry": Point(2, 0),
"t": datetime.datetime(2012, 1, 1, 8, 10, 0),
},
{
"geometry": Point(2, -1.98),
"t": datetime.datetime(2012, 1, 1, 8, 15, 0),
Expand All @@ -61,7 +82,13 @@ def test_simple_insert_with_movingpandas(session):
).set_index("t")
geo_df = GeoDataFrame(df, crs=CRS_METRIC)
traj = mpd.Trajectory(geo_df, 1)
session.add(GeogTripsWithMovingPandas(car_id=1, trip_id=1, trip=traj,))
session.add(
GeogTripsWithMovingPandas(
car_id=1,
trip_id=1,
trip=traj,
)
)
session.commit()

sql = session.query(GeogTripsWithMovingPandas).filter(
Expand Down Expand Up @@ -90,7 +117,13 @@ def test_wkt_values_are_valid(session):
).set_index("t")

with pytest.raises(StatementError):
session.add(GeogTrips(car_id=1, trip_id=1, trip=df,))
session.add(
GeogTrips(
car_id=1,
trip_id=1,
trip=df,
)
)
session.commit()


Expand All @@ -103,42 +136,86 @@ def test_str_values_are_invalid(session):
).set_index("t")

with pytest.raises(StatementError):
session.add(GeogTrips(car_id=1, trip_id=1, trip=df,))
session.add(
GeogTrips(
car_id=1,
trip_id=1,
trip=df,
)
)
session.commit()


def test_float_values_are_invalid(session):
df = pd.DataFrame(
[{"geometry": 8.1, "t": datetime.datetime(2012, 1, 1, 12, 6, 0)},]
[
{"geometry": 8.1, "t": datetime.datetime(2012, 1, 1, 12, 6, 0)},
]
).set_index("t")

with pytest.raises(StatementError):
session.add(GeogTrips(car_id=1, trip_id=1, trip=df,))
session.add(
GeogTrips(
car_id=1,
trip_id=1,
trip=df,
)
)
session.commit()


def test_mobility_functions(session):
df1 = pd.DataFrame(
[
{"geometry": Point(0, 0), "t": datetime.datetime(2012, 1, 1, 8, 0, 0),},
{"geometry": Point(2, 0), "t": datetime.datetime(2012, 1, 1, 8, 10, 0),},
{"geometry": Point(2, 1), "t": datetime.datetime(2012, 1, 1, 8, 15, 0),},
{
"geometry": Point(0, 0),
"t": datetime.datetime(2012, 1, 1, 8, 0, 0),
},
{
"geometry": Point(2, 0),
"t": datetime.datetime(2012, 1, 1, 8, 10, 0),
},
{
"geometry": Point(2, 1),
"t": datetime.datetime(2012, 1, 1, 8, 15, 0),
},
]
).set_index("t")

session.add(GeogTrips(car_id=10, trip_id=1, trip=df1,))
session.add(
GeogTrips(
car_id=10,
trip_id=1,
trip=df1,
)
)

session.commit()

df2 = pd.DataFrame(
[
{"geometry": Point(0, 0), "t": datetime.datetime(2012, 1, 1, 8, 5, 0),},
{"geometry": Point(1, 1), "t": datetime.datetime(2012, 1, 1, 8, 10, 0),},
{"geometry": Point(3, 3), "t": datetime.datetime(2012, 1, 1, 8, 20, 0),},
{
"geometry": Point(0, 0),
"t": datetime.datetime(2012, 1, 1, 8, 5, 0),
},
{
"geometry": Point(1, 1),
"t": datetime.datetime(2012, 1, 1, 8, 10, 0),
},
{
"geometry": Point(3, 3),
"t": datetime.datetime(2012, 1, 1, 8, 20, 0),
},
]
).set_index("t")

session.add(GeogTrips(car_id=20, trip_id=1, trip=df2,))
session.add(
GeogTrips(
car_id=20,
trip_id=1,
trip=df2,
)
)

session.commit()

Expand All @@ -163,7 +240,8 @@ def test_mobility_functions(session):

# Restriction to a given value
trips = session.query(
GeogTrips.car_id, func.asText(func.atValue(GeogTrips.trip, Point(2, 0).wkt)),
GeogTrips.car_id,
func.asText(func.atValue(GeogTrips.trip, Point(2, 0).wkt)),
).all()

assert len(trips) == 2
Expand Down Expand Up @@ -201,8 +279,14 @@ def test_mobility_functions(session):
T1 = alias(GeogTrips)
T2 = alias(GeogTrips)
trips = (
session.query(T1.c.car_id, T2.c.car_id, T1.c.trip.distance(T2.c.trip),)
.filter(T1.c.car_id < T2.c.car_id,)
session.query(
T1.c.car_id,
T2.c.car_id,
T1.c.trip.distance(T2.c.trip),
)
.filter(
T1.c.car_id < T2.c.car_id,
)
.all()
)

Expand Down Expand Up @@ -246,6 +330,6 @@ def haversine(lat1, lon1, lat2, lon2, **kwarg):
dlat = lat2 - lat1
dlon = lon2 - lon1
a = np.sin(dlat / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2
c = 2 * np.arctan2(a ** 0.5, (1 - a) ** 0.5)
c = 2 * np.arctan2(a**0.5, (1 - a) ** 0.5)
d = R * c
return round(d, 4)
Loading

0 comments on commit d3a9034

Please sign in to comment.