Skip to content

statistics.geometric_mean has no tests. Defer to 3.7? #72515

Closed

Description

@mdickinson
BPO 28328
Nosy @mdickinson, @ned-deily, @stevendaprano, @methane
Files
  • geometric_mean_tests.patch
  • geometric_mean.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/stevendaprano'
    closed_at = <Date 2019-02-21.06:25:11.553>
    created_at = <Date 2016-10-01.12:33:54.610>
    labels = ['type-bug', '3.7']
    title = 'statistics.geometric_mean has no tests. Defer to 3.7?'
    updated_at = <Date 2019-02-21.06:25:11.552>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2019-02-21.06:25:11.552>
    actor = 'methane'
    assignee = 'steven.daprano'
    closed = True
    closed_date = <Date 2019-02-21.06:25:11.553>
    closer = 'methane'
    components = []
    creation = <Date 2016-10-01.12:33:54.610>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['44920', '44941']
    hgrepos = []
    issue_num = 28328
    keywords = ['patch']
    message_count = 10.0
    messages = ['277811', '277812', '277837', '277851', '277950', '277951', '277996', '278026', '282604', '282607']
    nosy_count = 4.0
    nosy_names = ['mark.dickinson', 'ned.deily', 'steven.daprano', 'methane']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28328'
    versions = ['Python 3.7']

    Activity

    1. mdickinson commented on Oct 1, 2016

      @mdickinson
      MemberAuthor

      The newly-added statistics.geometric_mean function appears to have no tests at all, with the exception of a single doctest:

          >>> geometric_mean([1.10, 0.95, 1.12])
          1.0538483123382172

      Steve, Ned: what do you think about taking geometric_mean out of Python 3.6, leaving us time to get it into shape for 3.7? The implementation of geometric_mean is complicated, with many edge cases. The original code was committed without review in bpo-27181, and it currently suffers from some serious bugs: see bpo-27761, bpo-28111, bpo-28327 (the first of these affects only the tests for nroot; the second and third are behaviour bugs in geometric_mean). With the lack of tests, and Python 3.6 b2 looming, I think the best thing to do might be to defer the inclusion of geometric_mean to Python 3.7.

      I'll mark this as a release blocker until we decide what to do.

    2. stevendaprano commented on Oct 1, 2016

      @stevendaprano
      Member

      Unfortunately I'm in a pickle at the moment, I cannot build 3.6 on any
      of the machines I have available (three), and no time to upgrade them to
      something that will build 3.6. But I can provide some tests, if
      somebody is willing to review and check them in to 3.6.

    3. ned-deily commented on Oct 2, 2016

      @ned-deily
      Member

      I was hoping that the open issues could be resolved in time for b2 but that seems unlikely at this point. So I have to agree that this feature should be deferred to 3.7. Steven, can you make the necessary reverts on the 3.6 branch?

    4. stevendaprano commented on Oct 2, 2016

      @stevendaprano
      Member

      The newly-added statistics.geometric_mean function appears to have no
      tests at all

      That's weird and unfortunate. I certainly wrote tests, and I have a
      backup of them. I have no idea what happened.

      Attached is a patch that adds the tests, but obviously I haven't been
      able to run this until I resolve my gcc issues and can build 3.6 again.
      (I did run this some weeks ago, and they passed *then*, but I cannot be
      sure they still pass now.) If somebody would like to test this for me,
      it would be appreciated.

    5. methane commented on Oct 3, 2016

      @methane
      Member

      I run attached test, and saw following errors.

      On macOS 10.11 (XCode 8)

      $ hg summary
      parent: 104258:0d948a46c59a
       test_invalid_sequences seems don't have to stay in CAPITest.
      branch: 3.6
      commit: 1 modified, 1 unknown
      update: (current)
      
      
      $ ./python.exe -m test.test_statistics -v
      ...

      ======================================================================
      ERROR: test_negative_error (main.TestGeometricMean) (values=[-1])
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "/Users/inada-n/work/python/py36/Lib/test/test_statistics.py", line 1741, in test_negative_error
          self.assertRaises(exc, self.func, values)
        File "/Users/inada-n/work/python/py36/Lib/unittest/case.py", line 728, in assertRaises
          return context.handle('assertRaises', args, kwargs)
        File "/Users/inada-n/work/python/py36/Lib/unittest/case.py", line 177, in handle
          callable_obj(*args, **kwargs)
        File "/Users/inada-n/work/python/py36/Lib/statistics.py", line 567, in geometric_mean
          if isinstance(g, (numbers.Real, Decimal)):
      NameError: name 'g' is not defined

      ======================================================================
      ERROR: test_single_value (main.TestGeometricMean)
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "/Users/inada-n/work/python/py36/Lib/test/test_statistics.py", line 1587, in test_single_value
          self.assertEqual(self.func([x]), x)
        File "/Users/inada-n/work/python/py36/Lib/statistics.py", line 567, in geometric_mean
          if isinstance(g, (numbers.Real, Decimal)):
      NameError: name 'g' is not defined

      ======================================================================
      ERROR: test_singleton_lists (main.TestGeometricMean)
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "/Users/inada-n/work/python/py36/Lib/test/test_statistics.py", line 1762, in test_singleton_lists
          self.assertEqual(self.func([x]), x)
        File "/Users/inada-n/work/python/py36/Lib/statistics.py", line 567, in geometric_mean
          if isinstance(g, (numbers.Real, Decimal)):
      NameError: name 'g' is not defined

      ======================================================================
      FAIL: test_multiply_data_points (main.TestGeometricMean)
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "/Users/inada-n/work/python/py36/Lib/test/test_statistics.py", line 1796, in test_multiply_data_points
          self.assertApproxEqual(self.func(data), expected, rel=1e-13)
        File "/Users/inada-n/work/python/py36/Lib/test/test_statistics.py", line 227, in assertApproxEqual
          check(first, second, tol, rel, msg)
        File "/Users/inada-n/work/python/py36/Lib/test/test_statistics.py", line 247, in _check_approx_num
          raise self.failureException(msg)
      AssertionError:   6.27015835359916 != 695.9875772495068
        values differ by more than tol=0 and rel=1e-13
        -> absolute error = 689.7174188959076
        -> relative error = 0.990990990990991
    6. methane commented on Oct 3, 2016

      @methane
      Member

      Attached patch fixes first two errors.
      Last one error is from test. I've commented it in review tool.

    7. mdickinson commented on Oct 3, 2016

      @mdickinson
      MemberAuthor

      One more geometric_mean issue (the current code can enter an infinite loop for Decimal inputs): bpo-28351.

      Steve, I really think we should postpone to 3.7. I'm very happy to help out with all the necessary fixes, tests and review, but I'm not going to have time for that before 3.6b2. If we defer, that takes the pressure off a bit and lets us get a good solid implementation in for 3.7.

    8. stevendaprano commented on Oct 4, 2016

      @stevendaprano
      Member

      Steve, I really think we should postpone to 3.7. [...]

      If these fixes have to be in by the next beta (10th Oct), I fear that
      you are right. I can build up to changeset 103135:8b74e5528f35, but not
      beyond. I will be able to rectify that, but realistically it won't be
      before beta2.

      I expect that harmonic_mean is okay to stay in though?

      I feel frustrated at how close to complete geometric_mean is,
      disappointed that I can't work on it at the moment, and embarrassed that
      I'm letting the team down. Sorry for the extra work I've put you
      through.

      I can do the removals -- probably tonight.

    9. methane commented on Dec 7, 2016

      @methane
      Member

      3.6rc1 is released.
      What is status of this issue?

    10. methane commented on Dec 7, 2016

      @methane
      Member

      It had been rolled back.
      https://hg.python.org/cpython/rev/9dce0e41bedd

      Can we close this issue? bpo-27181 is still open.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)end of lifetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions