Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PyArray_SetBaseObject as ndarray.base is readonly property #201

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

rafalstapinski
Copy link
Contributor

@rafalstapinski rafalstapinski commented Apr 26, 2023

Change 1

Numpy 1.7 introduced the PyArray_SetBaseObject method of setting ndarray.base property as in recent versions base has become a read-only.

When compiling rawpy with a recent version of numpy (1.23.2) we get the following errors:

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                  raise RuntimeError('unsupported raw data')

              # ndarr must hold a reference to this object,
              # otherwise the underlying data gets lost when the RawPy instance gets out of scope
              # (which would trigger __dealloc__)
              ndarr.base = <PyObject*> self
                   ^
  ------------------------------------------------------------

  rawpy/_rawpy.pyx:509:17: Assignment to a read-only property

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          shape[2] = <np.npy_intp> self.processed_image.colors
          cdef np.ndarray ndarr
          ndarr = np.PyArray_SimpleNewFromData(3, shape,
                                               np.NPY_UINT8 if self.processed_image.bits == 8 else np.NPY_UINT16,
                                               self.processed_image.data)
          ndarr.base = <PyObject*> self
               ^
  ------------------------------------------------------------

  rawpy/_rawpy.pyx:1191:13: Assignment to a read-only property

Using numpy's PyArray_SetBaseObject fixes this (per: cython/cython#3690 (comment))

Breaking out from this thread: #171 (comment)

Change 2

Additionally the signature for skimage.filters.rank.median has changed, selem has changed to footprint so have updated that as well.

@rafalstapinski
Copy link
Contributor Author

@letmaik - any thoughts on setting a minimum numpy version for rawpy? Given this method was introduced in numpy==1.7, rawpy coupled with lower versions of numpy will fail.

@letmaik
Copy link
Owner

letmaik commented Apr 26, 2023

@rafalstapinski Setting a lower version bound is theoretically possible via version specifiers in install_requires in setup.py but I wouldn't bother to be honest as noone would try to build rawpy with such an ancient version of numpy, and I don't want to accurately maintain and update this lower bound in the future.

@letmaik
Copy link
Owner

letmaik commented Apr 26, 2023

Looks like something else is currently broken unrelated to your PR which makes CI fail, probably due to an update of scikit-image. Do you want to have a look by any chance? I'm a little busy currently.

@rafalstapinski
Copy link
Contributor Author

Yeah, I'll take a poke around.

@rafalstapinski
Copy link
Contributor Author

I don't have the full context of your reasoning behind allowing for trying to use median from skimage or opencv depending on availability. Totally fine with just using the new skimage signature (footprint, instead of selem) as scikit-image seems to have renamed it a few versions ago - but would it be better to just stick to one library (and making it a requirement) instead of trying for both?

@letmaik
Copy link
Owner

letmaik commented Apr 27, 2023 via email

@rafalstapinski
Copy link
Contributor Author

Sounds good - I updated the calls, want to run the pipelines again?

@rafalstapinski
Copy link
Contributor Author

Alrighty - looks like its all passing. Is your preference to break these out into two isolated changes, or just merge as is? Updated the PR message to reflect both changes.

@letmaik letmaik merged commit 99e0b1d into letmaik:main Apr 27, 2023
@letmaik
Copy link
Owner

letmaik commented Apr 27, 2023

Thanks again! Will kick off a new release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants