Coder Social home page Coder Social logo

Use == for comparisons about h5pyd HOT 5 CLOSED

hdfgroup avatar hdfgroup commented on September 26, 2024
Use == for comparisons

from h5pyd.

Comments (5)

jreadey avatar jreadey commented on September 26, 2024

Thanks for spotting that!

I made this change in a misguided attempt to fix this warning:

$ python test_dataset_getitem.py Test1DZeroFloat.test_mask filename: /home/john/h5pyd_test/dataset_test1dzerofloat.h5 /Users/jreadey/anaconda3/lib/python3.6/site-packages/h5pyd-0.3.2-py3.6.egg/h5pyd/_hl/dataset.py:581: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use array.size > 0 to check that an array is not empty. if args == (Ellipsis,) or args == tuple():

I'm not sure of the proper way to fix this though. Looks like the same code is in h5py as well.

For not I just reverted the change.

from h5pyd.

kalvdans avatar kalvdans commented on September 26, 2024

Thanks for a quick response! I understand now the reason for using is. It seems one first has to test the type and then the tuple contents:

isinstance(args, tuple) and args == (Ellipsis,)

Closing bug since the change was reverted. Good that you keep the code free from deprecation warnings.

from h5pyd.

jreadey avatar jreadey commented on September 26, 2024

You suggestion doesn't quite work since we still get the warning -- the comparison is between args[0] and Ellipsis which triggers the numpy warning.

This revised code seems to do the trick:

# === Check for zero-sized datasets =====
if self._shape is None or numpy.product(self._shape) == 0:
     # These are the only access methods NumPy allows for such objects
     if len(args) == 0 or len(args) == 1 and isinstance(args[0], tuple) and args[0] == Ellipsis:
           return numpy.empty(self._shape, dtype=new_dtype)

from h5pyd.

kalvdans avatar kalvdans commented on September 26, 2024

Sorry, but keeping adding a lot of special conditions won't help in the long run. I suggest playing around a bit in an interactive Python session to find out how isinstance works. isinstance(x, tuple) is a shorthand for type(x) == tuple

from h5pyd.

jreadey avatar jreadey commented on September 26, 2024

I do sort of know how ininstance works and use it in the code above.

This would be a bit cleaner I guess::

if len(args) == 0 or isinstance(args[0], tuple) and args[0] == Ellipsis:
           return numpy.empty(self._shape, dtype=new_dtype)

from h5pyd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.