Skip to content

Commit

Permalink
Moved geopandas file load out of constructor (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesanto authored Sep 21, 2023
1 parent c533e2e commit f1c5390
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ads/dataset/sampled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
OptionalDependency,
)

NATURAL_EARTH_DATASET = "naturalearth_lowres"

class PandasDataset(object):
"""
This class provides APIs that can work on a sampled dataset.
"""

@runtime_dependency(module="geopandas", install_from=OptionalDependency.GEO)
def __init__(
self,
sampled_df,
Expand All @@ -67,9 +67,7 @@ def __init__(
self.correlation = None
self.feature_dist_html_dict = {}
self.feature_types = metadata if metadata is not None else {}
self.world = geopandas.read_file(
geopandas.datasets.get_path("naturalearth_lowres")
)
self.world = None

self.numeric_columns = self.sampled_df.select_dtypes(
utils.numeric_pandas_dtypes()
Expand Down Expand Up @@ -562,7 +560,7 @@ def plot_gis_scatter(self, lon="longitude", lat="latitude", ax=None):
),
)
world = geopandas.read_file(
geopandas.datasets.get_path("naturalearth_lowres")
geopandas.datasets.get_path(NATURAL_EARTH_DATASET)
)
ax1 = world.plot(ax=ax, color="lightgrey", linewidth=0.5, edgecolor="white")
gdf.plot(ax=ax1, color="blue", markersize=10)
Expand Down Expand Up @@ -706,6 +704,12 @@ def _visualize_feature_distribution(self, html_widget):
gdf = geopandas.GeoDataFrame(
df, geometry=geopandas.points_from_xy(df["lon"], df["lat"])
)

if not self.world:
self.world = geopandas.read_file(
geopandas.datasets.get_path(NATURAL_EARTH_DATASET)
)

self.world.plot(
ax=ax, color="lightgrey", linewidth=0.5, edgecolor="white"
)
Expand Down

0 comments on commit f1c5390

Please sign in to comment.