Skip to content

Using abs in place of fabs to support more data types #5356

Closed

Description

@akiross

I have an np.array of decimal.Decimals, and I wanted to compute Median Absolute Deviation on the data, but it was not possible to do so because np.fabs is used to get the absolute value, but decimals have no fabs method so it fails:

return np.median((np.fabs(a-center))/c, axis=axis)

Things would work without problems if np.abs was used instead (and c converted to decimal, but this is on user's side). I suspect fabs is used to maintain compatibility with python2.

But, since python2 is going to be dropped in a year or so and the use of fabs reduces the number of data types supported, I would like to propose the switch to np.abs and allow to work with unusual data types. I worked just with MAD, but I can see fabs is used in other places of the code.

This can happen, of course, if you plan to drop support of python2 as well. But I might be mistaken, and fabs is not there for python2 :)

Activity

  1. josef-pkt commented on Oct 29, 2018

    @josef-pkt
    Member

    fabs can be replaced by np.abs without problems and python compatibility issues.
    (I never used python's abs.)
    I'm not sure why Skipper used fabs, I guess the main reason for fabs was computational efficiency.

    I have changed or have issues or PRs to change some fabs in other places to np.abs.

    aside: I'm surprised any function in statsmodels would work with decimal.Decimal

  2. added 3 commits that reference this issue on Jul 17, 2019
    021e003
    5c3e3a7
    2a56dbb
  3. added this to the 0.11 milestone on Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions