sunpy / ndcube

A base package for multi-dimensional contiguous and non-contiguous coordinate-aware arrays. "Maintainers": @danryanirish & @Cadair
http://docs.sunpy.org/projects/ndcube/
BSD 2-Clause "Simplified" License
44 stars 45 forks source link

Bad indentation in `NDCube.rebin` #696

Closed DanRyanIrish closed 2 months ago

DanRyanIrish commented 2 months ago

Describe the bug

https://github.com/sunpy/ndcube/blob/main/ndcube/ndcube.py#L1138

To Reproduce

import sunpy

sunpy.map.Map(...) etc

Screenshots

No response

System Details

No response

Installation method

No response

nabobalis commented 2 months ago

Did you fix it or was the report wrong?

ayshih commented 2 months ago

Looks correct to me

ayshih commented 2 months ago

The for...else structure is not very commonly used, so I can understand it causing confusion. An alternative could be to rewrite

for array_type, masked_type in ARRAY_MASK_MAP.items():
    if isinstance(self.data, array_type):
        break
else:
    masked_type = np.ma.masked_array
    warn_user("data and mask arrays of different or unrecognized types. Casting them into a numpy masked array.")

as

try:
    masked_type = next(array_type, masked_type in ARRAY_MASK_MAP.items() if isinstance(self.data, array_type))
except StopIteration:
    masked_type = np.ma.masked_array
    warn_user("data and mask arrays of different or unrecognized types. Casting them into a numpy masked array.")