Skip to content

Commit f1c5390

Browse files
authored
Moved geopandas file load out of constructor (#337)
1 parent c533e2e commit f1c5390

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ads/dataset/sampled_dataset.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
OptionalDependency,
4848
)
4949

50+
NATURAL_EARTH_DATASET = "naturalearth_lowres"
5051

5152
class PandasDataset(object):
5253
"""
5354
This class provides APIs that can work on a sampled dataset.
5455
"""
5556

56-
@runtime_dependency(module="geopandas", install_from=OptionalDependency.GEO)
5757
def __init__(
5858
self,
5959
sampled_df,
@@ -67,9 +67,7 @@ def __init__(
6767
self.correlation = None
6868
self.feature_dist_html_dict = {}
6969
self.feature_types = metadata if metadata is not None else {}
70-
self.world = geopandas.read_file(
71-
geopandas.datasets.get_path("naturalearth_lowres")
72-
)
70+
self.world = None
7371

7472
self.numeric_columns = self.sampled_df.select_dtypes(
7573
utils.numeric_pandas_dtypes()
@@ -562,7 +560,7 @@ def plot_gis_scatter(self, lon="longitude", lat="latitude", ax=None):
562560
),
563561
)
564562
world = geopandas.read_file(
565-
geopandas.datasets.get_path("naturalearth_lowres")
563+
geopandas.datasets.get_path(NATURAL_EARTH_DATASET)
566564
)
567565
ax1 = world.plot(ax=ax, color="lightgrey", linewidth=0.5, edgecolor="white")
568566
gdf.plot(ax=ax1, color="blue", markersize=10)
@@ -706,6 +704,12 @@ def _visualize_feature_distribution(self, html_widget):
706704
gdf = geopandas.GeoDataFrame(
707705
df, geometry=geopandas.points_from_xy(df["lon"], df["lat"])
708706
)
707+
708+
if not self.world:
709+
self.world = geopandas.read_file(
710+
geopandas.datasets.get_path(NATURAL_EARTH_DATASET)
711+
)
712+
709713
self.world.plot(
710714
ax=ax, color="lightgrey", linewidth=0.5, edgecolor="white"
711715
)

0 commit comments

Comments
 (0)