Skip to content

Commit 7bbc4e0

Browse files
y-pwesm
y-p
authored andcommitted
console_encode() will default to utf-8 when sys.stdin.encoding is None (ipnb)
1 parent d1bc126 commit 7bbc4e0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ def console_encode(value):
844844

845845
try:
846846
import sys
847-
return value.encode(sys.stdin.encoding, 'replace')
847+
return value.encode(sys.stdin.encoding or 'utf-8', 'replace')
848848
except (AttributeError, TypeError):
849849
return value.encode('ascii', 'replace')
850850

pandas/tests/test_common.py

+7
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ def test_2d_float32(self):
297297
expected[:, [2, 4]] = np.nan
298298
tm.assert_almost_equal(result, expected)
299299

300+
def test_console_encode(self):
301+
302+
# stub test
303+
# need to mock-out sys.stdin.encoding=None for real test
304+
result = com.console_encode(u"\u05d0")
305+
assert not result == '?'
306+
300307

301308
if __name__ == '__main__':
302309
import nose

0 commit comments

Comments
 (0)