aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-09-22 13:49:28 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-09-22 14:14:55 +0200
commit5c0c106c9fbdc9e5e189c8ba6903bbf70d803aba (patch)
tree531c9f6993bb5a6b00f4fcb1742417a1a3d15456 /src
parent1335bef6c3d0329678b2680dfc7435ad11db25df (diff)
downloadee-python-5c0c106c9fbdc9e5e189c8ba6903bbf70d803aba.tar.gz
ee-python-5c0c106c9fbdc9e5e189c8ba6903bbf70d803aba.tar.bz2
ee-python-5c0c106c9fbdc9e5e189c8ba6903bbf70d803aba.tar.xz
ee-python-5c0c106c9fbdc9e5e189c8ba6903bbf70d803aba.zip
o Better to_pandas for schematics.
Diffstat (limited to 'src')
-rw-r--r--src/ee/kicad/__init__.py24
-rw-r--r--src/ee/kicad/model.py4
2 files changed, 22 insertions, 6 deletions
diff --git a/src/ee/kicad/__init__.py b/src/ee/kicad/__init__.py
index b270ba1..adf8ddd 100644
--- a/src/ee/kicad/__init__.py
+++ b/src/ee/kicad/__init__.py
@@ -25,27 +25,39 @@ def to_pandas(obj: Any, **kwarg):
return False
return True
- def to_pandas_schematic(sch: Schematic, **kwarg):
+ def to_pandas_schematic(sch: Schematic):
+ # These fields will always be put first.
+ special_fields = ["ref", "ref_type", "ref_num", "value"]
def make_dict(c: Component):
- return {
+ fields = {
"ref": c.ref,
"ref_type": c.ref_type,
"ref_num": c.ref_num,
- "value": c.value
+ "value": c.value,
+ "footprint": c.footprint,
}
+ fields.update({f.name:f.value for f in c.fields if f.is_custom})
+ return fields
components = sch.components
filters = []
- if not kwarg.get("include_pwr", False):
+ include_pwr = kwarg.get("include_pwr", False)
+ if not include_pwr:
filters.append(lambda c: not c.is_pwr)
+ include_flg = kwarg.get("include_flg", False)
+ if not include_flg:
+ filters.append(lambda c: c.ref_type != "#FLG")
+
data = [make_dict(c) for c in components if run_filter(filters, c)]
+ columns = set([key for row in data for key in list(row)]) - set(special_fields)
+ columns = special_fields + list(columns)
- return pandas.DataFrame(data=data, columns=["ref", "ref_type", "ref_num", "value"]).\
+ return pandas.DataFrame(data=data, columns=columns).\
set_index("ref").\
- sort_index()
+ sort_values(["ref_type", "ref_num"])
if isinstance(obj, Schematic):
return to_pandas_schematic(obj)
diff --git a/src/ee/kicad/model.py b/src/ee/kicad/model.py
index 519a978..f112e72 100644
--- a/src/ee/kicad/model.py
+++ b/src/ee/kicad/model.py
@@ -43,6 +43,10 @@ class ComponentField(object):
def position(self):
return self._position
+ @property
+ def is_custom(self):
+ return self._index >= len(ComponentField.names)
+
@total_ordering
class Component(object):