yzhao062/Pyod

View on GitHub
pyod/utils/data.py

Summary

Maintainability
D
2 days
Test Coverage

File data.py has 480 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

# -*- coding: utf-8 -*-
"""Utility functions for manipulating data
"""
# Author: Yue Zhao <zhaoy@cmu.edu>
# Author: Yahya Almardeny <almardeny@gmail.com>
Severity: Minor
Found in pyod/utils/data.py - About 7 hrs to fix

    Function generate_data_clusters has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    def generate_data_clusters(n_train=1000, n_test=500, n_clusters=2,
                               n_features=2, contamination=0.1, size='same',
                               density='same', dist=0.25, random_state=None,
                               return_in_clusters=False):
        """Utility function to generate synthesized data in clusters.
    Severity: Minor
    Found in pyod/utils/data.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function generate_data_categorical has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def generate_data_categorical(n_train=1000, n_test=500, n_features=2,
                                  n_informative=2, n_category_in=2,
                                  n_category_out=2, contamination=0.1,
                                  shuffle=True, random_state=None):
        """Utility function to generate synthesized categorical data.
    Severity: Minor
    Found in pyod/utils/data.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function generate_data has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Invalid

    def generate_data(n_train=1000, n_test=500, n_features=2, contamination=0.1,
    Severity: Major
    Found in pyod/utils/data.py - About 1 hr to fix

      Function generate_data_clusters has 10 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def generate_data_clusters(n_train=1000, n_test=500, n_clusters=2,
      Severity: Major
      Found in pyod/utils/data.py - About 1 hr to fix

        Function generate_data_categorical has 9 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def generate_data_categorical(n_train=1000, n_test=500, n_features=2,
        Severity: Major
        Found in pyod/utils/data.py - About 1 hr to fix

          Function _generate_data has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Invalid

          def _generate_data(n_inliers, n_outliers, n_features, coef, offset,
          Severity: Major
          Found in pyod/utils/data.py - About 1 hr to fix

            Function check_consistent_shape has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def check_consistent_shape(X_train, y_train, X_test, y_test, y_train_pred,
            Severity: Minor
            Found in pyod/utils/data.py - About 45 mins to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Invalid

                  if n_nan > 0:
                      X = np.r_[X, np.full((n_nan, n_features), np.NaN)]
                      y = np.r_[y, np.full((n_nan), np.NaN)]
              Severity: Major
              Found in pyod/utils/data.py and 1 other location - About 3 hrs to fix
              pyod/utils/data.py on lines 81..83

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 63.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Invalid

                  if n_inf > 0:
                      X = np.r_[X, np.full((n_inf, n_features), np.infty)]
                      y = np.r_[y, np.full((n_inf), np.infty)]
              Severity: Major
              Found in pyod/utils/data.py and 1 other location - About 3 hrs to fix
              pyod/utils/data.py on lines 77..79

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 63.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 3 locations. Consider refactoring.
              Open

                  if isinstance(n_informative, int):
                      check_parameter(n_informative, low=0, high=n_features + 1, param_name='n_informative')
                  else:
                      raise ValueError("n_informative should be int, got %s" % n_informative)
              Severity: Major
              Found in pyod/utils/data.py and 2 other locations - About 1 hr to fix
              pyod/utils/data.py on lines 607..610
              pyod/utils/data.py on lines 612..615

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 46.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 3 locations. Consider refactoring.
              Open

                  if isinstance(n_category_out, int):
                      check_parameter(n_category_out, low=0, high=n_outliers + 1, param_name='n_category_out')
                  else:
                      raise ValueError("n_category_out should be int, got %s" % n_category_out)
              Severity: Major
              Found in pyod/utils/data.py and 2 other locations - About 1 hr to fix
              pyod/utils/data.py on lines 588..591
              pyod/utils/data.py on lines 607..610

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 46.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 3 locations. Consider refactoring.
              Open

                  if isinstance(n_category_in, int):
                      check_parameter(n_category_in, low=0, high=n_inliers + 1, param_name='n_category_in')
                  else:
                      raise ValueError("n_category_in should be int, got %s" % n_category_in)
              Severity: Major
              Found in pyod/utils/data.py and 2 other locations - About 1 hr to fix
              pyod/utils/data.py on lines 588..591
              pyod/utils/data.py on lines 612..615

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 46.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  if isinstance(contamination, (float, int)):
                      check_parameter(contamination, low=0, high=0.5,
                                      param_name='contamination')
                  else:
                      raise ValueError(
              Severity: Major
              Found in pyod/utils/data.py and 1 other location - About 1 hr to fix
              pyod/utils/data.py on lines 593..597

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 43.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  if isinstance(contamination, (float, int)):
                      check_parameter(contamination, low=0, high=0.5,
                                      param_name='contamination')
                  else:
                      raise ValueError("contamination should be float, got %s" % contamination)
              Severity: Major
              Found in pyod/utils/data.py and 1 other location - About 1 hr to fix
              pyod/utils/data.py on lines 385..390

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 43.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  if isinstance(n_features, int):
                      check_parameter(n_features, low=1, param_name='n_features')
                  else:
                      raise ValueError("n_features should be int, got %s" % n_features)
              Severity: Major
              Found in pyod/utils/data.py and 5 other locations - About 55 mins to fix
              pyod/models/lmdd.py on lines 32..35
              pyod/utils/data.py on lines 375..378
              pyod/utils/data.py on lines 573..576
              pyod/utils/data.py on lines 578..581
              pyod/utils/data.py on lines 583..586

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 37.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  if isinstance(n_train, int):
                      check_parameter(n_train, low=1, param_name='n_train')
                  else:
                      raise ValueError("n_train should be int, got %s" % n_train)
              Severity: Major
              Found in pyod/utils/data.py and 5 other locations - About 55 mins to fix
              pyod/models/lmdd.py on lines 32..35
              pyod/utils/data.py on lines 375..378
              pyod/utils/data.py on lines 380..383
              pyod/utils/data.py on lines 578..581
              pyod/utils/data.py on lines 583..586

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 37.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  if isinstance(n_test, int):
                      check_parameter(n_test, low=0, param_name='n_test')
                  else:
                      raise ValueError("n_test should be int, got %s" % n_test)
              Severity: Major
              Found in pyod/utils/data.py and 5 other locations - About 55 mins to fix
              pyod/models/lmdd.py on lines 32..35
              pyod/utils/data.py on lines 375..378
              pyod/utils/data.py on lines 380..383
              pyod/utils/data.py on lines 573..576
              pyod/utils/data.py on lines 583..586

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 37.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  if isinstance(n_features, int):
                      check_parameter(n_features, low=0, param_name='n_features')
                  else:
                      raise ValueError("n_features should be int, got %s" % n_features)
              Severity: Major
              Found in pyod/utils/data.py and 5 other locations - About 55 mins to fix
              pyod/models/lmdd.py on lines 32..35
              pyod/utils/data.py on lines 375..378
              pyod/utils/data.py on lines 380..383
              pyod/utils/data.py on lines 573..576
              pyod/utils/data.py on lines 578..581

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 37.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 6 locations. Consider refactoring.
              Open

                  if isinstance(n_clusters, int):
                      check_parameter(n_clusters, low=1, param_name='n_clusters')
                  else:
                      raise ValueError("n_clusters should be int, got %s" % n_clusters)
              Severity: Major
              Found in pyod/utils/data.py and 5 other locations - About 55 mins to fix
              pyod/models/lmdd.py on lines 32..35
              pyod/utils/data.py on lines 380..383
              pyod/utils/data.py on lines 573..576
              pyod/utils/data.py on lines 578..581
              pyod/utils/data.py on lines 583..586

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 37.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status