-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,10 @@ def read_abbreviations(): | |
|
|
||
| # create the mtype:abbreviation dict | ||
| get_abbreviations = [tuple(i.rstrip().split(":")) for i in get_abbreviations if i.rstrip() if not i.startswith("#")] | ||
| get_abbreviations = dict((i[0], [j.lstrip() for j in i[1].split(",")]) for i in get_abbreviations) | ||
| get_abbreviations = { | ||
| i[0]: [j.lstrip() for j in i[1].split(",")] for i in get_abbreviations | ||
| } | ||
|
|
||
|
|
||
| # create inverse abbrev:mtype/ftype | ||
| get_mtype_ftype = {i: k for k in get_abbreviations for i in get_abbreviations[k]} | ||
|
|
@@ -141,7 +144,7 @@ def extract_add_dialect_block(cls, block): | |
| * *list of additionals* | ||
| * *str, dialect* | ||
| """ | ||
| if not 'dialect' in block: | ||
| if 'dialect' not in block: | ||
|
Comment on lines
-144
to
+147
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return block, '' | ||
| parts = block.split(",") | ||
| dialect = [p for p in parts if "dialect" in p][0].replace("dialect=", "") | ||
|
|
@@ -161,8 +164,8 @@ def from_folder(cls, folder, filter=None): | |
| RockPy.minfo: | ||
| """ | ||
|
|
||
| if filter == None: | ||
| filter = dict() | ||
| if filter is None: | ||
| filter = {} | ||
|
Comment on lines
-164
to
+168
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
|
|
||
| dfiles = [os.path.join(folder, i) for i in os.listdir(folder) if not i.startswith("#")] | ||
|
|
||
|
|
@@ -175,12 +178,7 @@ def from_folder(cls, folder, filter=None): | |
| cls.log().debug("cant read file: %s" % os.path.basename(f)) | ||
| continue | ||
|
|
||
| if minfo is None: | ||
| minfo = finfo | ||
| else: | ||
| # append subsequent minfos | ||
| minfo = minfo + finfo | ||
|
|
||
| minfo = finfo if minfo is None else minfo + finfo | ||
| return minfo | ||
|
|
||
| @classmethod | ||
|
|
@@ -204,7 +202,7 @@ def from_file(cls, fpath): | |
| splits = filename.split("#") | ||
|
|
||
| # check if RockPy compatible e.g. first part must be len(4) | ||
| if not len(splits[0].split("_")) == 4: | ||
| if len(splits[0].split("_")) != 4: | ||
|
Comment on lines
-207
to
+205
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| cls.log().debug('filename << %s >> does not conform to the RockPy file naming scheme. At least 3 elements (sname, mtype, ftype) ' | ||
| 'have to be given, separated by \'_\' '%filename) | ||
| return | ||
|
|
@@ -234,17 +232,25 @@ def from_file(cls, fpath): | |
| additional, dialect = (None, None) | ||
|
|
||
| # comment | ||
| if len(splits) > 4: | ||
| comment = splits[4] | ||
| else: | ||
| comment = None | ||
|
|
||
| return cls(snames=snames, mtypes=mtypes, ftype=ftype, fpath=fpath, sgroups=sgroups, | ||
| dialect=dialect, | ||
| mass=mass, massunit=massunit if massunit else "kg", | ||
| height=height, heightunit=heightunit if heightunit else "m", | ||
| diameter=diameter, diameterunit=diameterunit if diameterunit else "m", | ||
| series=series, comment=comment, additional=additional, suffix=suffix) | ||
| comment = splits[4] if len(splits) > 4 else None | ||
| return cls( | ||
| snames=snames, | ||
| mtypes=mtypes, | ||
| ftype=ftype, | ||
| fpath=fpath, | ||
| sgroups=sgroups, | ||
| dialect=dialect, | ||
| mass=mass, | ||
| massunit=massunit or "kg", | ||
| height=height, | ||
| heightunit=heightunit or "m", | ||
| diameter=diameter, | ||
| diameterunit=diameterunit or "m", | ||
| series=series, | ||
| comment=comment, | ||
| additional=additional, | ||
| suffix=suffix, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, **kwargs): | ||
|
|
@@ -341,10 +347,8 @@ def __init__( | |
| else: | ||
| self.lengthunit = RockPy.core.utils.to_list(lengthunit) | ||
|
|
||
| if series is not None: | ||
| # if only one series and not three | ||
| if len(series) == 3 and not len(series[0]) == 3: | ||
| series = tuple2list_of_tuples(to_tuple(series)) | ||
| if series is not None and len(series) == 3 and len(series[0]) != 3: | ||
| series = tuple2list_of_tuples(to_tuple(series)) | ||
|
Comment on lines
-344
to
+351
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
|
|
||
| self.series = [series] | ||
|
|
||
|
|
@@ -372,7 +376,7 @@ def get_measurement_block(cls, sgroups, snames, mtypes, ftype): | |
| """ | ||
| mtypes = (RockPy.classname_to_abbrev[i][0] for i in mtypes) | ||
| block = [sgroups, snames, mtypes, ftype] | ||
| if not all(i for i in block): | ||
| if not all(block): | ||
|
Comment on lines
-375
to
+379
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| raise ImportError("sname, mtype, ftype needed for minfo to be generated") | ||
| return "_".join((RockPy.core.utils.tuple2str(b) for b in block)) | ||
|
|
||
|
|
@@ -419,11 +423,8 @@ def get_sample_block(cls, | |
|
|
||
| for i in range(n): | ||
| b = block[i] | ||
| if not all(j for j in b): | ||
| if i == 0: | ||
| aux = "XXmg" | ||
| else: | ||
| aux = "XXmm" | ||
| if not all(b): | ||
| aux = "XXmg" if i == 0 else "XXmm" | ||
|
Comment on lines
-422
to
+427
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| else: | ||
| out.append("".join(map(str, b))) | ||
| return ",".join(out) | ||
|
|
@@ -475,7 +476,7 @@ def new_filenames(self): | |
| blocks = [measurement_block, sample_block, series_block, add_block] | ||
| # work through blocks backwards throw out blocks that are empty, | ||
| # if ones is not empty, stop. | ||
| for i, block in enumerate(blocks[::-1]): | ||
| for block in blocks[::-1]: | ||
|
Comment on lines
-478
to
+479
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if not block: | ||
| blocks.pop() | ||
| else: | ||
|
|
@@ -509,9 +510,9 @@ def getImportHelper(self, snames=None, mtypes=None): | |
| mtypes = RockPy.to_tuple(mtypes) | ||
|
|
||
| for ih in self._gen_dicts: | ||
| if all(i for i in snames) and ih["snames"] not in snames: | ||
| if all(snames) and ih["snames"] not in snames: | ||
| continue | ||
| if all(i for i in mtypes) and ih["mtypes"] not in mtypes: | ||
| if all(mtypes) and ih["mtypes"] not in mtypes: | ||
|
Comment on lines
-512
to
+515
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| continue | ||
| a = self.__class__.from_dict(**ih) | ||
| yield a | ||
|
|
@@ -583,9 +584,8 @@ def return_file_infos(self): | |
| Returns: | ||
| dict: | ||
| """ | ||
| out = {} | ||
| out = {'snames': list_or_item(self.snames[0])} | ||
|
|
||
| out['snames'] = list_or_item(self.snames[0]) | ||
|
Comment on lines
-586
to
-588
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| out['sgroups'] = list_or_item(self.sgroups[0]) | ||
| out['mtypes'] = list_or_item(self.mtypes[0]) | ||
| out['ftype'] = self.ftype[0] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,21 +166,20 @@ def _has_specimen(self, specimen): | |
| bool: `True` if file contains `specimen` otherwise `False` | ||
|
|
||
| """ | ||
| if specimen not in self.data['specimen'].values: | ||
| Ftype.log().error('CANNOT IMPORT -- sobj_name not in ftype_data specimen list.') | ||
| Ftype.log().error('wrong sample name?') | ||
| Ftype.log().error('These samples exist: %s' % set(self.data['specimens'])) | ||
| return False | ||
| else: | ||
| if specimen in self.data['specimen'].values: | ||
| return True | ||
| Ftype.log().error('CANNOT IMPORT -- sobj_name not in ftype_data specimen list.') | ||
| Ftype.log().error('wrong sample name?') | ||
| Ftype.log().error('These samples exist: %s' % set(self.data['specimens'])) | ||
| return False | ||
|
Comment on lines
-169
to
+174
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def to_si_units(self): | ||
| """ converts each numeric column in self.data to SI internal_units TODO: write to out_units | ||
| """ | ||
| Q_ = ureg.Quantity | ||
| for col in self.data.columns: | ||
| if col in self.in_units: | ||
| if not col in self.units: | ||
| if col not in self.units: | ||
|
Comment on lines
-183
to
+182
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.log().warning( | ||
| 'Unit of data column << {} >> has no internal unit equivalent. The input unit is << {:P} >>.'.format( | ||
| col, self.in_units[col])) | ||
|
|
@@ -296,7 +295,6 @@ def is_implemented(ftype): | |
| """ | ||
| if ftype in RockPy.implemented_ftypes: | ||
| return True | ||
| else: | ||
| RockPy.log.error( | ||
| f'Ftype << {ftype} >> is not implemented. Check RockPy.implemented_ftypes for which ftypes are.') | ||
| return False | ||
| RockPy.log.error( | ||
| f'Ftype << {ftype} >> is not implemented. Check RockPy.implemented_ftypes for which ftypes are.') | ||
| return False | ||
|
Comment on lines
-299
to
+300
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
read_abbreviationsrefactored with the following changes:collection-builtin-to-comprehension)