Skip to content

Commit d115c86

Browse files
author
y-p
committed
ENH: UnicodeWriter (CSV) now supports quoting=csv.QUOTE_NONNUMERIC
1 parent 2e1001d commit d115c86

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pandas/core/common.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,17 @@ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
933933
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
934934
self.stream = f
935935
self.encoder = codecs.getincrementalencoder(encoding)()
936+
self.quoting=kwds.get("quoting",None)
936937

937938
def writerow(self, row):
938-
row = [x if isinstance(x, basestring) else pprint_thing(x) for x in row]
939-
self.writer.writerow([s.encode("utf-8") for s in row])
939+
def _check_as_is(x):
940+
return (self.quoting == csv.QUOTE_NONNUMERIC and \
941+
is_number(x)) or isinstance(x, str)
942+
943+
row = [x if _check_as_is(x)
944+
else pprint_thing(x).encode('utf-8') for x in row]
945+
946+
self.writer.writerow([s for s in row])
940947
# Fetch UTF-8 output from the queue ...
941948
data = self.queue.getvalue()
942949
data = data.decode("utf-8")

0 commit comments

Comments
 (0)