Skip to content

Commit 6c3d0ee

Browse files
authored
Merge pull request #1899 from materialsproject/fix-init-columns
Fix init columns
2 parents 6a73345 + ca4cc21 commit 6c3d0ee

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

mpcontribs-client/mpcontribs/client/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
ureg.define("atom = 1")
116116
ureg.define("bohr_magneton = e * hbar / (2 * m_e) = µᵇ = µ_B = mu_B")
117117
ureg.define("electron_mass = 9.1093837015e-31 kg = mₑ = m_e")
118+
ureg.define("sccm = cm³/min")
118119

119120
LOG_LEVEL = os.environ.get("MPCONTRIBS_CLIENT_LOG_LEVEL", "INFO")
120121
log_level = getattr(logging, LOG_LEVEL.upper())
@@ -1402,7 +1403,7 @@ def get_attachment(self, aid_or_md5: str) -> Type[Attachment]:
14021403
self.attachments.getAttachmentById(pk=aid, _fields=["_all"]).result()
14031404
)
14041405

1405-
def init_columns(self, columns: dict = None) -> dict:
1406+
def init_columns(self, columns: dict = None, name: str = None) -> dict:
14061407
"""initialize columns for a project to set their order and desired units
14071408
14081409
The `columns` field of a project tracks the minima and maxima of each `data` field
@@ -1435,8 +1436,11 @@ def init_columns(self, columns: dict = None) -> dict:
14351436
Args:
14361437
columns (dict): dictionary mapping data column to its unit
14371438
"""
1438-
if not self.project:
1439-
raise MPContribsClientError("initialize client with project argument!")
1439+
name = self.project or name
1440+
if not name:
1441+
raise MPContribsClientError(
1442+
"initialize client with project or set `name` argument!"
1443+
)
14401444

14411445
columns = flatten(columns or {}, reducer="dot")
14421446

@@ -1497,9 +1501,7 @@ def init_columns(self, columns: dict = None) -> dict:
14971501

14981502
# TODO catch unsupported column renaming or implement solution
14991503
# reconcile with existing columns
1500-
resp = self.projects.getProjectByName(
1501-
pk=self.project, _fields=["columns"]
1502-
).result()
1504+
resp = self.projects.getProjectByName(pk=name, _fields=["columns"]).result()
15031505
existing_columns = {}
15041506

15051507
for col in resp["columns"]:
@@ -1556,9 +1558,7 @@ def init_columns(self, columns: dict = None) -> dict:
15561558
if not valid:
15571559
raise MPContribsClientError(error)
15581560

1559-
return self.projects.updateProjectByName(
1560-
pk=self.project, project=payload
1561-
).result()
1561+
return self.projects.updateProjectByName(pk=name, project=payload).result()
15621562

15631563
def delete_contributions(self, query: dict = None, timeout: int = -1):
15641564
"""Remove all contributions for a query

0 commit comments

Comments
 (0)