Skip to content

Commit

Permalink
added dropna to accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Franz committed Oct 30, 2024
1 parent 3acd74e commit 5b7d940
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pandapower/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, pandas_obj):
@staticmethod
def _validate(obj):
try:
if not obj.apply(loads).apply(isinstance, args=(GeoJSON,)).all():
if not obj.dropna().apply(loads).apply(isinstance, args=(GeoJSON,)).all():
raise AttributeError("Can only use .geojson accessor with geojson string values!")
except Exception as e:
raise AttributeError(f"Can only use .geojson accessor with geojson string values!: {e}")
Expand All @@ -53,15 +53,15 @@ def extract_coords(x):

@property
def coords(self):
return self._obj.apply(loads).apply(self.extract_coords)
return self._obj.dropna().apply(loads).apply(self.extract_coords)

@property
def as_geo_object(self):
return self._obj.apply(loads)
return self._obj.dropna().apply(loads)

@property
def type(self):
return self._obj.apply(loads).apply(lambda x: str(x["type"]))
return self._obj.dropna().apply(loads).apply(lambda x: str(x["type"]))


def create_empty_network(name="", f_hz=50., sn_mva=1, add_stdtypes=True):
Expand Down
2 changes: 2 additions & 0 deletions pandapower/test/api/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def test_geo_accessor():
std_type="48-AL1/8-ST1A 10.0",
geodata=[[(1, 1), (2, 2), (3, 3)], [(1, 1), (1, 2)]],
)
pp.create_line(net, b1, b2, 1.5, std_type="48-AL1/8-ST1A 10.0")

assert len(net.line.geo.geojson.coords) == 2
assert net.line.geo.geojson.coords.at[l[0]] == [(1, 1), (2, 2), (3, 3)]
assert net.line.geo.geojson.coords.at[l[1]] == [(1, 1), (1, 2)]
assert net.bus.geo.geojson.coords.at[b1] == (1, 1)
Expand Down

0 comments on commit 5b7d940

Please sign in to comment.