@@ -1021,6 +1021,10 @@ def __init__(
1021
1021
self ._order_categoricals = order_categoricals
1022
1022
self ._encoding = ""
1023
1023
self ._chunksize = chunksize
1024
+ if self ._chunksize is not None and (
1025
+ not isinstance (chunksize , int ) or chunksize <= 0
1026
+ ):
1027
+ raise ValueError ("chunksize must be a positive integer when set." )
1024
1028
1025
1029
# State variables for the file
1026
1030
self ._has_string_data = False
@@ -1486,6 +1490,10 @@ def _read_strls(self) -> None:
1486
1490
self .GSO [str (v_o )] = decoded_va
1487
1491
1488
1492
def __next__ (self ) -> DataFrame :
1493
+ if self ._chunksize is None :
1494
+ raise ValueError (
1495
+ "chunksize must be set to a positive integer to use as an iterator."
1496
+ )
1489
1497
return self .read (nrows = self ._chunksize or 1 )
1490
1498
1491
1499
def get_chunk (self , size : Optional [int ] = None ) -> DataFrame :
@@ -1769,7 +1777,7 @@ def _do_convert_categoricals(
1769
1777
vl = value_label_dict [label ]
1770
1778
keys = np .array ([k for k in vl .keys ()])
1771
1779
column = data [col ]
1772
- if column .isin (keys ).all () and self . _chunksize :
1780
+ if self . _chunksize is not None and column .isin (keys ).all ():
1773
1781
# If all categories are in the keys and we are iterating,
1774
1782
# use the same keys for all chunks. If some are missing
1775
1783
# value labels, then we will fall back to the categories
0 commit comments