Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved geopandas file load out of constructor #337

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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