Skip to content

discretize_model should work or throw an error for non-model callable input #2274

Closed

Description

@cdeil

Currently discretize_model silently fails (i.e. returns None) for a non-model callable as input:

>>> from astropy.convolution import discretize_model
>>> def my_model(x):
...     return 42 * x
>>> array = discretize_model(my_model, x_range=(-3, 3))
>>> print(array)
None

One option would be to remove all the isinstance checks and slightly change the API (add an argument callable_n_dim=1) to be able to process any callable as input.

Another option would be to fix the isinstance checking to throw a TypeError if something other than a Parametric1DModel or a Parametric2DModel is passed.

cc @astrofrog @adonath

Activity

  1. cdeil commented on Apr 30, 2014

    @cdeil
    MemberAuthor

    @astrofrog @adonath What do you think would be a good fix for this bug?
    (I've mentioned two options above, but there might be better ones?)

  2. eteq commented on May 5, 2014

    @eteq
    Member

    @cdeil - I don't understand why callable_n_dim is necessary in your example. Can't it just be inferred from whether or not y_range is present? (E.g., y_range == None implies 1D, otherwise 2D). In that case, I'd say its appropriate only to check that it's consistent if a FittableModel is present. So that would give the bahvior that, if y_range==None and it's a Fittable2DModel, or y_range != None and its a Fittable1DModel, an error should be given. But if it's a callable, use y_range being None or not to infer the dimension.

  3. added this to the v1.0.0 milestone on May 9, 2014
  4. added 5 commits that reference this issue on Dec 17, 2014
    ad1a0a0
    97df5ec
    8cf68e1
    9a82024
    3b43ba4
  5. added a commit that references this issue on Dec 19, 2014
    de7f482
  6. embray commented on Dec 19, 2014

    @embray
    Member

    Fixed by #3220; thanks @adonath !

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