From 2640d648a1e4a12f7b81c55f8c0ca6d3f912a69e Mon Sep 17 00:00:00 2001 From: Sharon Fitzpatrick Date: Thu, 22 Feb 2024 09:30:34 -0800 Subject: [PATCH] #228 update transects str and repr funcs --- src/coastseg/transects.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/coastseg/transects.py b/src/coastseg/transects.py index b01fdd77..2c3fb35a 100644 --- a/src/coastseg/transects.py +++ b/src/coastseg/transects.py @@ -261,7 +261,13 @@ def __str__(self): # Get first 5 rows as a string first_rows = self.gdf.head().to_string() # Get CRS information - crs_info = f"CRS: {self.gdf.crs}" if self.gdf.crs else "CRS: None" + if self.gdf.empty: + crs_info = "CRS: None" + else: + if self.gdf is not None and hasattr(self.gdf, 'crs'): + crs_info = f"CRS: {self.gdf.crs}" if self.gdf.crs else "CRS: None" + else: + crs_info = "CRS: None" ids = "" if "id" in self.gdf.columns: ids = self.gdf["id"].astype(str) @@ -273,7 +279,13 @@ def __repr__(self): # Get first 5 rows as a string first_rows = self.gdf.head().to_string() # Get CRS information - crs_info = f"CRS: {self.gdf.crs}" if self.gdf.crs else "CRS: None" + if self.gdf.empty: + crs_info = "CRS: None" + else: + if self.gdf is not None and hasattr(self.gdf, 'crs'): + crs_info = f"CRS: {self.gdf.crs}" if self.gdf.crs else "CRS: None" + else: + crs_info = "CRS: None" ids = "" if "id" in self.gdf.columns: ids = self.gdf["id"].astype(str)