From 549422f81528904daca71ea1c5326d79ce88ccf0 Mon Sep 17 00:00:00 2001 From: charalampos papaloizou Date: Sat, 29 Nov 2014 13:56:34 +0000 Subject: [PATCH] BUG: fixed chunksize guessed to 0 (py3 only). #8621 --- doc/source/whatsnew/v0.15.2.txt | 1 + pandas/core/format.py | 2 +- pandas/tests/test_frame.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index eacccaa7cba92..bed8ace26b82d 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -99,6 +99,7 @@ Bug Fixes - Bug in ``BlockManager`` where setting values with different type would break block integrity (:issue:`8850`) - Bug in ``DatetimeIndex`` when using ``time`` object as key (:issue:`8667`) - Fix negative step support for label-based slices (:issue:`8753`) +- Fixed division by 0 when reading big csv files in python 3 (:issue:`8621`) Old behavior: diff --git a/pandas/core/format.py b/pandas/core/format.py index 89973754a861c..dbfe78d93bdcd 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -1247,7 +1247,7 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='', float_format=None, self.data = [None] * ncols if chunksize is None: - chunksize = (100000 / (len(self.cols) or 1)) or 1 + chunksize = (100000 // (len(self.cols) or 1)) or 1 self.chunksize = int(chunksize) self.data_index = obj.index diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index fc031afe728dc..f14b0bff80545 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -6462,6 +6462,14 @@ def test_to_csv_chunking(self): rs = read_csv(filename,index_col=0) assert_frame_equal(rs, aa) + def test_to_csv_wide_frame_formatting(self): + # Issue #8621 + df = DataFrame(np.random.randn(1, 100010), columns=None, index=None) + with ensure_clean() as filename: + df.to_csv(filename, header=False, index=False) + rs = read_csv(filename, header=None) + assert_frame_equal(rs, df) + def test_to_csv_bug(self): f1 = StringIO('a,1.0\nb,2.0') df = DataFrame.from_csv(f1, header=None)