Skip to content

Commit df9b686

Browse files
authored
add docstring to from/to method (#266)
1 parent 1401b34 commit df9b686

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dpdata/system.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,20 @@ def pick_atom_idx(self, idx, nopbc=None):
12151215
new_sys.append(ss.pick_atom_idx(idx, nopbc=nopbc))
12161216
return new_sys
12171217

1218+
def get_cls_name(cls: object) -> str:
1219+
"""Returns the fully qualified name of a class, such as `np.ndarray`.
1220+
1221+
Parameters
1222+
----------
1223+
cls : object
1224+
the class
1225+
1226+
Returns
1227+
-------
1228+
str
1229+
the fully qualified name of a class
1230+
"""
1231+
return ".".join([cls.__module__, cls.__name__])
12181232

12191233
def add_format_methods():
12201234
"""Add format methods to System, LabeledSystem, and MultiSystems.
@@ -1237,6 +1251,7 @@ def get_func(ff):
12371251
# ff is not initized when defining from_format so cannot be polluted
12381252
def from_format(self, file_name, **kwargs):
12391253
return self.from_fmt_obj(ff(), file_name, **kwargs)
1254+
from_format.__doc__ = "Read data from :class:`%s` format." % (get_cls_name(ff))
12401255
return from_format
12411256

12421257
setattr(System, method, get_func(formatcls))
@@ -1247,6 +1262,7 @@ def from_format(self, file_name, **kwargs):
12471262
def get_func(ff):
12481263
def to_format(self, *args, **kwargs):
12491264
return self.to_fmt_obj(ff(), *args, **kwargs)
1265+
to_format.__doc__ = "Dump data to :class:`%s` format." % (get_cls_name(ff))
12501266
return to_format
12511267

12521268
setattr(System, method, get_func(formatcls))

0 commit comments

Comments
 (0)