common dim_messages should use warnings

Issue #174 resolved
Bradley Dice created an issue

Instead of using logger.warning, the freud.common dim_message should be output using warnings.warn(dim_message). Also the test for freud.common should ensure that the warning is raised.

Comments (5)

  1. Vyas Ramasubramani

    Why should we change this? There's already a TypeError raised, the logger is only for debugging purposes. Although tbh I'm not even sure that should be retained since the error should be sufficient for debugging purposes, we may want to remove it entirely.

  2. Bradley Dice reporter

    Sorry, I didn't specify the reason that I wanted to do this. This message pops up every time that tests are run, like this:

    $ python -m unittest discover .
    ..................................ref_points must be a 2 dimensional array
    ........s.s.s.s.s..................................s..............................................
    ----------------------------------------------------------------------
    Ran 132 tests in 53.374s
    
    OK (skipped=6)
    

    I think this is a little confusing and it's not clear if something is wrong with the tests until you dig in and find where it's coming from. Using warnings and assertRaises is a better solution.

  3. Vyas Ramasubramani

    Got it. My follow-ups:

    1. Do you think it actually serves a purpose? Is there any reason to not just remove it entirely?
    2. If you actually think that it is worth keeping as a debugging tool, why not change it to logger.debug? That would better address the fact that it's meant as a debugging tool, and not as a real warning since it should error out anyway unless the subsequent TypeError is explicitly caught.
    3. If we wanted to add a test for warnings, it would be a bit more complicated than that. We would need to use the catch_warnings function in the warnings package, assertRaises won't catch warnings.
  4. Log in to comment