@@ -1038,6 +1038,10 @@ def __init__(
10381038 self ._order_categoricals = order_categoricals
10391039 self ._encoding = ""
10401040 self ._chunksize = chunksize
1041+ if self ._chunksize is not None and (
1042+ not isinstance (chunksize , int ) or chunksize <= 0
1043+ ):
1044+ raise ValueError ("chunksize must be a positive integer when set." )
10411045
10421046 # State variables for the file
10431047 self ._has_string_data = False
@@ -1503,6 +1507,10 @@ def _read_strls(self) -> None:
15031507 self .GSO [str (v_o )] = decoded_va
15041508
15051509 def __next__ (self ) -> DataFrame :
1510+ if self ._chunksize is None :
1511+ raise ValueError (
1512+ "chunksize must be set to a positive integer to use as an iterator."
1513+ )
15061514 return self .read (nrows = self ._chunksize or 1 )
15071515
15081516 def get_chunk (self , size : Optional [int ] = None ) -> DataFrame :
@@ -1786,7 +1794,7 @@ def _do_convert_categoricals(
17861794 vl = value_label_dict [label ]
17871795 keys = np .array ([k for k in vl .keys ()])
17881796 column = data [col ]
1789- if column .isin (keys ).all () and self . _chunksize :
1797+ if self . _chunksize is not None and column .isin (keys ).all ():
17901798 # If all categories are in the keys and we are iterating,
17911799 # use the same keys for all chunks. If some are missing
17921800 # value labels, then we will fall back to the categories
0 commit comments