Skip to content

Commit

Permalink
Print Vector.info() by default (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet authored Jun 13, 2024
1 parent 1c729f7 commit 47346f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion geoutils/raster/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ def info(self, stats: bool = False, verbose: bool = True) -> None | str:
not calculate statistics.
:param verbose: If set to True (default) will directly print to screen and return None
:returns: summary string or None.
:returns: Summary string or None.
"""
as_str = [
f"Driver: {self.driver} \n",
Expand Down
18 changes: 16 additions & 2 deletions geoutils/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,20 @@ def __str__(self) -> str:

return str(self.ds.__str__())

def info(self) -> str:
@overload
def info(self, verbose: Literal[True] = ...) -> None:
...

@overload
def info(self, verbose: Literal[False]) -> str:
...

def info(self, verbose: bool = True) -> str | None:
"""
Summarize information about the vector.
:param verbose: If set to True (default) will directly print to screen and return None
:returns: Information about vector attributes.
"""
as_str = [ # 'Driver: {} \n'.format(self.driver),
Expand All @@ -161,7 +171,11 @@ def info(self) -> str:
f"Attributes: {self.ds.columns.tolist()}",
]

return "".join(as_str)
if verbose:
print("".join(as_str))
return None
else:
return "".join(as_str)

def plot(
self,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ def test_copy(self) -> None:

assert vector2.ds.shape[0] < self.glacier_outlines.ds.shape[0]

def test_info(self) -> None:

v = gu.Vector(GLACIER_OUTLINES_URL)

# Check default runs without error (prints to screen)
output = v.info()
assert output is None

# Otherwise returns info
output2 = v.info(verbose=False)
assert isinstance(output2, str)
list_prints = ["Filename", "Coordinate System", "Extent", "Number of features", "Attributes"]
assert all(p in output2 for p in list_prints)

def test_query(self) -> None:
vector2 = self.glacier_outlines.query("NAME == 'Ayerbreen'")

Expand Down

0 comments on commit 47346f0

Please sign in to comment.