mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Load before getting size in __array_interface__
This commit is contained in:
		
							parent
							
								
									415455d01b
								
							
						
					
					
						commit
						6a931861fe
					
				| 
						 | 
				
			
			@ -4,7 +4,7 @@ import pytest
 | 
			
		|||
 | 
			
		||||
from PIL import Image
 | 
			
		||||
 | 
			
		||||
from .helper import assert_deep_equal, assert_image, hopper
 | 
			
		||||
from .helper import assert_deep_equal, assert_image, hopper, skip_unless_feature
 | 
			
		||||
 | 
			
		||||
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -219,6 +219,13 @@ def test_zero_size():
 | 
			
		|||
    assert im.size == (0, 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@skip_unless_feature("libtiff")
 | 
			
		||||
def test_load_first():
 | 
			
		||||
    with Image.open("Tests/images/g4_orientation_5.tif") as im:
 | 
			
		||||
        a = numpy.array(im)
 | 
			
		||||
        assert a.shape == (88, 590)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_bool():
 | 
			
		||||
    # https://github.com/python-pillow/Pillow/issues/2044
 | 
			
		||||
    a = numpy.zeros((10, 2), dtype=bool)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -686,11 +686,7 @@ class Image:
 | 
			
		|||
    @property
 | 
			
		||||
    def __array_interface__(self):
 | 
			
		||||
        # numpy array interface support
 | 
			
		||||
        new = {}
 | 
			
		||||
        shape, typestr = _conv_type_shape(self)
 | 
			
		||||
        new["shape"] = shape
 | 
			
		||||
        new["typestr"] = typestr
 | 
			
		||||
        new["version"] = 3
 | 
			
		||||
        new = {"version": 3}
 | 
			
		||||
        try:
 | 
			
		||||
            if self.mode == "1":
 | 
			
		||||
                # Binary images need to be extended from bits to bytes
 | 
			
		||||
| 
						 | 
				
			
			@ -709,6 +705,7 @@ class Image:
 | 
			
		|||
                    if parse_version(numpy.__version__) < parse_version("1.23"):
 | 
			
		||||
                        warnings.warn(e)
 | 
			
		||||
            raise
 | 
			
		||||
        new["shape"], new["typestr"] = _conv_type_shape(self)
 | 
			
		||||
        return new
 | 
			
		||||
 | 
			
		||||
    def __getstate__(self):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user