Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 22, 2021

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from MikeVolk December 22, 2021 16:32
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -25 to +28
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
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function read_abbreviations refactored with the following changes:

Comment on lines -144 to +147
if not 'dialect' in block:
if 'dialect' not in block:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ImportHelper.extract_add_dialect_block refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -164 to +168
if filter == None:
filter = dict()
if filter is None:
filter = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ImportHelper.from_folder refactored with the following changes:

This removes the following comments ( why? ):

# append subsequent minfos

Comment on lines -207 to +205
if not len(splits[0].split("_")) == 4:
if len(splits[0].split("_")) != 4:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ImportHelper.from_file refactored with the following changes:

Comment on lines -344 to +351
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))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ImportHelper.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# if only one series and not three

"""

return True if result in self._results.keys() else False
return result in self._results.keys()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.has_result refactored with the following changes:

add = 'mean_'
else:
add = ''
add = 'mean_' if self.is_mean else ''
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.__repr__ refactored with the following changes:

Comment on lines -537 to +540
def reset_data(self): # todo rewrite new data pandas
def reset_data(self): # todo rewrite new data pandas
"""
Resets all data back to the original state. Deepcopies _raw_data back to _data and resets correction
"""
midx = self.__class__._mids.index(self.mid)

self.log().debug(f'Resetting the data')
self.log().debug('Resetting the data')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.reset_data refactored with the following changes:

Comment on lines -638 to +635
return True if self.initial_state else False
return bool(self.initial_state)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.has_initial_state refactored with the following changes:

Comment on lines -751 to +749
else:
series = (None, np.nan, None) # no series
return [series]
series = (None, np.nan, None) # no series
return [series]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.series refactored with the following changes:

Comment on lines -778 to +782
if sval is not None:
sval = to_tuple(sval)
if method == 'all':
return True if all(i in self.svals for i in sval) else False
if method == 'any':
return True if any(i in self.svals for i in sval) else False
if method == 'none':
return True if not any(i in self.svals for i in sval) else False
else:
return True if not self.svals else False
if sval is None:
return not self.svals
sval = to_tuple(sval)
if method == 'all':
return all(i in self.svals for i in sval)
if method == 'any':
return any(i in self.svals for i in sval)
if method == 'none':
return all(i not in self.svals for i in sval)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.has_sval refactored with the following changes:

Comment on lines -812 to +815
if stype is not None:
stype = to_tuple(stype)
if method == 'all':
return True if all(i in self.stypes for i in stype) else False
if method == 'any':
return True if any(i in self.stypes for i in stype) else False
if method == 'none':
return True if not any(i in self.stypes for i in stype) else False
else:
return True if not self.stypes else False
if stype is None:
return not self.stypes
stype = to_tuple(stype)
if method == 'all':
return all(i in self.stypes for i in stype)
if method == 'any':
return any(i in self.stypes for i in stype)
if method == 'none':
return all(i not in self.stypes for i in stype)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.has_stype refactored with the following changes:

Comment on lines -843 to +845
if series is not None:
series = tuple2list_of_tuples(series)
if method == 'all':
return True if all(i in self.series for i in series) else False
if method == 'any':
return True if any(i in self.series for i in series) else False
if method == 'none':
return True if not any(i in self.svals for i in series) else False
else:
return True if self._series else False
if series is None:
return bool(self._series)
series = tuple2list_of_tuples(series)
if method == 'all':
return all(i in self.series for i in series)
if method == 'any':
return any(i in self.series for i in series)
if method == 'none':
return all(i not in self.svals for i in series)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.has_series refactored with the following changes:

Comment on lines -962 to +957
otherseries = (s for s in other.series if not s[0] in ignore_stypes)

if all(i in otherseries for i in selfseries):
return True
otherseries = (s for s in other.series if s[0] not in ignore_stypes)

else:
return False
return all(i in otherseries for i in selfseries)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.equal_series refactored with the following changes:

  • Simplify conditional into return statement (return-identity)
  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -978 to +967
norm_initial_state=True, **options): # todo check if works
norm_initial_state=True, **options): # todo check if works
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Measurement.normalize refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -186 to +182
info.loc[self.name, 'sample groups'] = self._samplegroups if self._samplegroups else 'None'
info.loc[self.name, 'sample groups'] = self._samplegroups or 'None'

mtypes = [(mt, len(self.get_measurement(mtype=mt))) for mt in self.mtypes]

if mtypes:
info.loc[self.name, 'mtypes'] = ', '.join(self.mtypes) # if len(mtypes) > 1 else mtypes[0]
else:
info.loc[self.name, 'mtypes'] = None

info.loc[self.name, 'mtypes'] = ', '.join(self.mtypes) if mtypes else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.info refactored with the following changes:

This removes the following comments ( why? ):

# if len(mtypes) > 1 else mtypes[0]

Comment on lines -361 to +358
if self.samplegroups:
sgroups = self.samplegroups
else:
sgroups = None

sgroups = self.samplegroups or None
""" DATA import from mass, height, diameter, len ... """

# check for parameters in kwargs (i.e. mass = '12mg'
parameters = ['mass', 'diameter', 'height', 'x_len', 'y_len', 'z_len']
if create_parameters:
if any([(k in parameters) and (kwargs[k] is not None) for k in kwargs.keys()]):
# check for parameters in kwargs (i.e. mass = '12mg'
parameters = ['mass', 'diameter', 'height', 'x_len', 'y_len', 'z_len']
if any(
(k in parameters) and (kwargs[k] is not None)
for k in kwargs.keys()
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.add_measurement refactored with the following changes:

Comment on lines -507 to +494
return set(series for m in self.measurements for series in m.series)
return {series for m in self.measurements for series in m.series}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.series refactored with the following changes:

Comment on lines -524 to +511
return set(stype for m in self.measurements for stype in m.stypes if stype)
return {stype for m in self.measurements for stype in m.stypes if stype}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.stypes refactored with the following changes:

Comment on lines -534 to +523
return set(series[1] for series in self.series
if isinstance(series[1], (int, float))
if not np.isnan(series[1]))
return {series[1] for series in self.series
if isinstance(series[1], (int, float))
if not np.isnan(series[1])}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.svals refactored with the following changes:

Comment on lines -546 to +533
return set(series[2] for series in self.series)
return {series[2] for series in self.series}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.sunits refactored with the following changes:

Comment on lines -557 to +544
return set(m.mtype for m in self.measurements)
return {m.mtype for m in self.measurements}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample.mtypes refactored with the following changes:

Comment on lines -720 to +707
svals = set(sval for m in self.mean_measurements for sval in m.svals)
svals = {sval for m in self.mean_measurements for sval in m.svals}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sample._convert_sval_range refactored with the following changes:

Comment on lines -43 to +45
if not name:
self.name = time.strftime("%Y%m%d:%H%M")
else:
self.name = name

self.name = time.strftime("%Y%m%d:%H%M") if not name else name
# create empty dictionary for storing samples
self._samples = dict() # {'sname':'sobj'}
self._samples = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Study.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# {'sname':'sobj'}

Comment on lines -64 to +60
for s in sorted(self._samples.values()):
yield s
yield from sorted(self._samples.values())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Study.__iter__ refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

idx = i

if not idx == len(item) - 1:
if idx != len(item) - 1:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function split_num_alph refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

else:
xyz = args[0]

xyz = kwargs.pop('xyz') if 'xyz' in kwargs else args[0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function import_submodules.handle_shape_dtype.conversion refactored with the following changes:

Comment on lines -495 to -503
if not any(i == 3 for i in s):
if all(i != 3 for i in s):
raise ValueError('At least one dimension needs to be length 3')
# for [x,y,z] or [d,i,m]
if s == (3,):
if len(set(np.shape(elem) for elem in xyz)) != 1:
if len({np.shape(elem) for elem in xyz}) != 1:
raise ValueError('Number of elements ix xyz is inconsistent')
xyz = np.array(xyz).reshape((1, 3))

# for array like [[x1,x2,... ],[y1,y2,...],[z1,z2,...]],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function import_submodules.maintain_n3_shape refactored with the following changes:

This removes the following comments ( why? ):

# for array like [[x1,x2,... ],[y1,y2,...],[z1,z2,...]],

else:
level = int(row[num_index:6])

level = 0 if not row[num_index:6] else int(row[num_index:6])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Cif._separate_row refactored with the following changes:

Comment on lines -239 to +235
corrected = sample_means - holder_means
return corrected
return sample_means - holder_means
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Cif._correct_holder refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 22, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.58%.

Quality metrics Before After Change
Complexity 6.73 ⭐ 6.28 ⭐ -0.45 👍
Method Length 62.00 🙂 61.17 🙂 -0.83 👍
Working memory 9.73 🙂 9.67 🙂 -0.06 👍
Quality 64.21% 🙂 64.79% 🙂 0.58% 👍
Other metrics Before After Change
Lines 9212 9105 -107
Changed files Quality Before Quality After Quality Change
RockPy/core/file_io.py 63.98% 🙂 64.84% 🙂 0.86% 👍
RockPy/core/ftype.py 61.37% 🙂 61.95% 🙂 0.58% 👍
RockPy/core/measurement.py 62.95% 🙂 65.16% 🙂 2.21% 👍
RockPy/core/result.py 67.51% 🙂 68.65% 🙂 1.14% 👍
RockPy/core/sample.py 55.39% 🙂 56.07% 🙂 0.68% 👍
RockPy/core/study.py 77.71% ⭐ 77.58% ⭐ -0.13% 👎
RockPy/core/utils.py 70.22% 🙂 71.84% 🙂 1.62% 👍
RockPy/ftypes/cif.py 60.30% 🙂 61.17% 🙂 0.87% 👍
RockPy/ftypes/cryomag.py 84.75% ⭐ 84.62% ⭐ -0.13% 👎
RockPy/ftypes/jr6.py 69.74% 🙂 69.45% 🙂 -0.29% 👎
RockPy/ftypes/mpms.py 88.89% ⭐ 88.93% ⭐ 0.04% 👍
RockPy/ftypes/tools.py 95.27% ⭐ 96.97% ⭐ 1.70% 👍
RockPy/ftypes/variforc.py 53.57% 🙂 53.85% 🙂 0.28% 👍
RockPy/ftypes/vsm.py 55.95% 🙂 56.66% 🙂 0.71% 👍
RockPy/packages/generic/parameter.py 71.81% 🙂 71.95% 🙂 0.14% 👍
RockPy/packages/magnetism/measurements.py 64.85% 🙂 64.58% 🙂 -0.27% 👎
RockPy/packages/magnetism/simulations.py 60.68% 🙂 61.39% 🙂 0.71% 👍
RockPy/packages/magnetism/tools.py 27.07% 😞 27.13% 😞 0.06% 👍
RockPy/packages/xrd/tools.py 82.03% ⭐ 83.69% ⭐ 1.66% 👍
RockPy/tests/test_study.py 88.21% ⭐ 88.35% ⭐ 0.14% 👍
RockPy/tools/compute.py 68.90% 🙂 68.55% 🙂 -0.35% 👎
RockPy/tools/plotting.py 64.39% 🙂 64.43% 🙂 0.04% 👍
RockPy/tools/pressure.py 91.13% ⭐ 91.88% ⭐ 0.75% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
RockPy/core/measurement.py Measurement.normalize 38 ⛔ 337 ⛔ 20 ⛔ 12.75% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
RockPy/packages/magnetism/measurements.py Hysteresis.data_gridding 28 😞 352 ⛔ 19 ⛔ 17.37% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
RockPy/core/sample.py Sample.add_measurement 24 😞 284 ⛔ 19 ⛔ 21.60% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
RockPy/packages/magnetism/tools.py ThellierStepMaker 30 😞 233 ⛔ 13 😞 27.13% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
RockPy/core/result.py Result.__call__ 34 ⛔ 218 ⛔ 10 😞 31.48% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants