Skip to content

Commit

Permalink
Run black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Diviloper committed May 12, 2024
1 parent 626f5bf commit a301f6e
Show file tree
Hide file tree
Showing 29 changed files with 507 additions and 567 deletions.
57 changes: 30 additions & 27 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,52 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'PyMEOS'
copyright = '2023, Víctor Diví'
author = 'Víctor Diví'
release = '1.1.3'
project = "PyMEOS"
copyright = "2023, Víctor Diví"
author = "Víctor Diví"
release = "1.1.3"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
import os
import sys

sys.path.insert(0, os.path.abspath('../pymeos_cffi'))
sys.path.insert(0, os.path.abspath('../pymeos'))
sys.path.insert(0, os.path.abspath("../pymeos_cffi"))
sys.path.insert(0, os.path.abspath("../pymeos"))

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx',
'myst_nb',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"myst_nb",
]

nb_execution_mode = "off"

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '_build',
'**.ipynb_checkpoints']
autodoc_member_order = 'bysource'
templates_path = ["_templates"]
exclude_patterns = [
"_build",
"Thumbs.db",
".DS_Store",
"_build",
"**.ipynb_checkpoints",
]
autodoc_member_order = "bysource"

# -- Intersphinx config --------
intersphinx_mapping = {
'asyncpg': ('https://magicstack.github.io/asyncpg/current/', None),
'psycopg': ('https://www.psycopg.org/psycopg3/docs/', None),
'psycopg2': ('https://www.psycopg.org/docs/', None),
'shapely': ('https://shapely.readthedocs.io/en/stable/', None),
'python': ('https://docs.python.org/3', None)
"asyncpg": ("https://magicstack.github.io/asyncpg/current/", None),
"psycopg": ("https://www.psycopg.org/psycopg3/docs/", None),
"psycopg2": ("https://www.psycopg.org/docs/", None),
"shapely": ("https://shapely.readthedocs.io/en/stable/", None),
"python": ("https://docs.python.org/3", None),
}

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_book_theme'
html_static_path = ['_static']
html_theme = "sphinx_book_theme"
html_static_path = ["_static"]

import requests

Expand All @@ -58,15 +63,13 @@ def download_file(url, dest_path):
# Ensure folder for destination file exists
os.makedirs(os.path.dirname(dest_path), exist_ok=True)

with open(dest_path, 'wb') as file:
with open(dest_path, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)


prefix = "https://raw.githubusercontent.com/MobilityDB/PyMEOS-Examples/main/"
download_file(f"{prefix}PyMEOS_Examples/AIS.ipynb", "src/examples/AIS.ipynb")
download_file(
f"{prefix}PyMEOS_Examples/AIS.ipynb",
"src/examples/AIS.ipynb")
download_file(
f"{prefix}PyMEOS_Examples/BerlinMOD.ipynb",
"src/examples/BerlinMOD.ipynb")
f"{prefix}PyMEOS_Examples/BerlinMOD.ipynb", "src/examples/BerlinMOD.ipynb"
)
4 changes: 1 addition & 3 deletions pymeos/aggregators/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ def _add(
interval_converted = (
timedelta_to_interval(interval)
if isinstance(interval, timedelta)
else pg_interval_in(interval, -1)
if isinstance(interval, str)
else None
else pg_interval_in(interval, -1) if isinstance(interval, str) else None
)
origin_converted = (
datetime_to_timestamptz(origin)
Expand Down
128 changes: 64 additions & 64 deletions pymeos/boxes/stbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class STBox:
_mobilitydb_name = "stbox"

def _get_box(
self,
other: Union[shp.BaseGeometry, STBox, Temporal, Time],
allow_space_only: bool = True,
allow_time_only: bool = False,
self,
other: Union[shp.BaseGeometry, STBox, Temporal, Time],
allow_space_only: bool = True,
allow_time_only: bool = False,
) -> STBox:
if allow_space_only and isinstance(other, shp.BaseGeometry):
other_box = geo_to_stbox(geo_to_gserialized(other, self.geodetic()))
Expand All @@ -68,31 +68,31 @@ def _get_box(

# ------------------------- Constructors ----------------------------------
def __init__(
self,
string: Optional[str] = None,
*,
xmin: Optional[Union[str, float]] = None,
xmax: Optional[Union[str, float]] = None,
ymin: Optional[Union[str, float]] = None,
ymax: Optional[Union[str, float]] = None,
zmin: Optional[Union[str, float]] = None,
zmax: Optional[Union[str, float]] = None,
tmin: Optional[Union[str, datetime]] = None,
tmax: Optional[Union[str, datetime]] = None,
tmin_inc: bool = True,
tmax_inc: bool = True,
geodetic: bool = False,
srid: Optional[int] = None,
_inner=None,
self,
string: Optional[str] = None,
*,
xmin: Optional[Union[str, float]] = None,
xmax: Optional[Union[str, float]] = None,
ymin: Optional[Union[str, float]] = None,
ymax: Optional[Union[str, float]] = None,
zmin: Optional[Union[str, float]] = None,
zmax: Optional[Union[str, float]] = None,
tmin: Optional[Union[str, datetime]] = None,
tmax: Optional[Union[str, datetime]] = None,
tmin_inc: bool = True,
tmax_inc: bool = True,
geodetic: bool = False,
srid: Optional[int] = None,
_inner=None,
):
assert (_inner is not None) or (string is not None) != (
(
xmin is not None
and xmax is not None
and ymin is not None
and ymax is not None
)
or (tmin is not None and tmax is not None)
(
xmin is not None
and xmax is not None
and ymin is not None
and ymax is not None
)
or (tmin is not None and tmax is not None)
), (
"Either string must be not None or at least a bound pair (xmin/max"
" and ymin/max, or tmin/max) must be not None"
Expand All @@ -106,10 +106,10 @@ def __init__(
tstzspan = None
hast = tmin is not None and tmax is not None
hasx = (
xmin is not None
and xmax is not None
and ymin is not None
and ymax is not None
xmin is not None
and xmax is not None
and ymin is not None
and ymax is not None
)
hasz = zmin is not None and zmax is not None
if hast:
Expand Down Expand Up @@ -224,9 +224,9 @@ def from_time(time: Time) -> STBox:

@staticmethod
def from_geometry_time(
geometry: shp.BaseGeometry,
time: Union[datetime, TsTzSpan],
geodetic: bool = False,
geometry: shp.BaseGeometry,
time: Union[datetime, TsTzSpan],
geodetic: bool = False,
) -> STBox:
"""
Returns a `STBox` from a space and time dimension.
Expand Down Expand Up @@ -272,9 +272,9 @@ def from_tpoint(temporal: TPoint) -> STBox:

@staticmethod
def from_expanding_bounding_box(
value: Union[shp.BaseGeometry, TPoint, STBox],
expansion: float,
geodetic: Optional[bool] = False,
value: Union[shp.BaseGeometry, TPoint, STBox],
expansion: float,
geodetic: Optional[bool] = False,
) -> STBox:
"""
Returns a `STBox` from a `shp.BaseGeometry`, `TPoint` or `STBox` instance,
Expand Down Expand Up @@ -661,7 +661,7 @@ def scale_time(self, duration: timedelta) -> STBox:
return self.shift_scale_time(duration=duration)

def shift_scale_time(
self, shift: Optional[timedelta] = None, duration: Optional[timedelta] = None
self, shift: Optional[timedelta] = None, duration: Optional[timedelta] = None
) -> STBox:
"""
Returns a new `STBox` with the time dimension shifted by `shift` and
Expand All @@ -681,7 +681,7 @@ def shift_scale_time(
:meth:`TsTzSpan.shift_scale`
"""
assert (
shift is not None or duration is not None
shift is not None or duration is not None
), "shift and scale deltas must not be both None"
result = stbox_shift_scale_time(
self._inner,
Expand Down Expand Up @@ -792,7 +792,7 @@ def __mul__(self, other):

# ------------------------- Topological Operations ------------------------
def is_adjacent(
self, other: Union[shp.BaseGeometry, STBox, Temporal, Time]
self, other: Union[shp.BaseGeometry, STBox, Temporal, Time]
) -> bool:
"""
Returns whether ``self`` and `other` are adjacent. Two spatiotemporal
Expand All @@ -815,7 +815,7 @@ def is_adjacent(
)

def is_contained_in(
self, container: Union[shp.BaseGeometry, STBox, Temporal, Time]
self, container: Union[shp.BaseGeometry, STBox, Temporal, Time]
) -> bool:
"""
Returns whether ``self`` is contained in `container`. Note that for
Expand Down Expand Up @@ -1177,7 +1177,7 @@ def is_over_or_after(self, other: Union[Box, Temporal, Time]) -> bool:

# ------------------------- Distance Operations ---------------------------
def nearest_approach_distance(
self, other: Union[shp.BaseGeometry, STBox, TPoint]
self, other: Union[shp.BaseGeometry, STBox, TPoint]
) -> float:
"""
Returns the distance between the nearest points of ``self`` and `other`.
Expand Down Expand Up @@ -1277,11 +1277,11 @@ def quad_split(self) -> Union[List[List[STBox]], List[List[List[STBox]]]]:
]

def tile(
self,
size: Optional[float] = None,
duration: Optional[Union[timedelta, str]] = None,
origin: Optional[shp.BaseGeometry] = None,
start: Union[datetime, str, None] = None,
self,
size: Optional[float] = None,
duration: Optional[Union[timedelta, str]] = None,
origin: Optional[shp.BaseGeometry] = None,
start: Union[datetime, str, None] = None,
) -> List[STBox]:
"""
Returns a list of `STBox` instances representing the tiles of
Expand All @@ -1306,35 +1306,35 @@ def tile(
stbox_tile_list
"""
sz = size or (
max(
self.xmax() - self.xmin(),
self.ymax() - self.ymin(),
(self.zmax() - self.zmin() if self.has_z() else 0),
)
+ 1
max(
self.xmax() - self.xmin(),
self.ymax() - self.ymin(),
(self.zmax() - self.zmin() if self.has_z() else 0),
)
+ 1
)
dt = (
timedelta_to_interval(duration)
if isinstance(duration, timedelta)
else pg_interval_in(duration, -1)
if isinstance(duration, str)
else None
else pg_interval_in(duration, -1) if isinstance(duration, str) else None
)
st = (
datetime_to_timestamptz(start)
if isinstance(start, datetime)
else pg_timestamptz_in(start, -1)
if isinstance(start, str)
else pg_timestamptz_in("2000-01-03", -1)
if self.has_t()
else 0
else (
pg_timestamptz_in(start, -1)
if isinstance(start, str)
else pg_timestamptz_in("2000-01-03", -1) if self.has_t() else 0
)
)
gs = (
geo_to_gserialized(origin, self.geodetic())
if origin is not None
else pgis_geography_in("Point(0 0 0)", -1)
if self.geodetic()
else pgis_geometry_in("Point(0 0 0)", -1)
else (
pgis_geography_in("Point(0 0 0)", -1)
if self.geodetic()
else pgis_geometry_in("Point(0 0 0)", -1)
)
)
tiles, count = stbox_tile_list(self._inner, sz, sz, sz, dt, gs, st)
return [STBox(_inner=tiles + i) for i in range(count)]
Expand Down
8 changes: 5 additions & 3 deletions pymeos/boxes/tbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,11 @@ def tile(
st = (
datetime_to_timestamptz(start)
if isinstance(start, datetime)
else pg_timestamptz_in(start, -1)
if isinstance(start, str)
else pg_timestamptz_in("2000-01-03", -1)
else (
pg_timestamptz_in(start, -1)
if isinstance(start, str)
else pg_timestamptz_in("2000-01-03", -1)
)
)
if self._is_float():
tiles, count = tfloatbox_tile_list(self._inner, size, dt, origin, st)
Expand Down
24 changes: 8 additions & 16 deletions pymeos/collections/base/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,16 @@ def as_hexwkb(self) -> str:

# ------------------------- Conversions -----------------------------------
@overload
def to_span(self: Type[IntSet]) -> IntSpan:
...
def to_span(self: Type[IntSet]) -> IntSpan: ...

@overload
def to_span(self: Type[FloatSet]) -> FloatSpan:
...
def to_span(self: Type[FloatSet]) -> FloatSpan: ...

@overload
def to_span(self: Type[TsTzSet]) -> TsTzSpan:
...
def to_span(self: Type[TsTzSet]) -> TsTzSpan: ...

@overload
def to_span(self: Type[DateSet]) -> DateSpan:
...
def to_span(self: Type[DateSet]) -> DateSpan: ...

def to_span(self) -> Span:
"""
Expand All @@ -176,20 +172,16 @@ def to_span(self) -> Span:
return _CollectionFactory.create_collection(set_span(self._inner))

@overload
def to_spanset(self: Type[IntSet]) -> IntSpanSet:
...
def to_spanset(self: Type[IntSet]) -> IntSpanSet: ...

@overload
def to_spanset(self: Type[FloatSet]) -> FloatSpanSet:
...
def to_spanset(self: Type[FloatSet]) -> FloatSpanSet: ...

@overload
def to_spanset(self: Type[TsTzSet]) -> TsTzSpanSet:
...
def to_spanset(self: Type[TsTzSet]) -> TsTzSpanSet: ...

@overload
def to_spanset(self: Type[DateSet]) -> DateSpanSet:
...
def to_spanset(self: Type[DateSet]) -> DateSpanSet: ...

def to_spanset(self) -> SpanSet:
"""
Expand Down
Loading

0 comments on commit a301f6e

Please sign in to comment.