Skip to content

Commit

Permalink
Support unicode for file system neo4j csv loader in py3 (#259)
Browse files Browse the repository at this point in the history
* Support unicode for file system neo4j csv loader in py3

* Revert "Support unicode for file system neo4j csv loader in py3"

This reverts commit 23f3ae9.

* Fix py3 loader unicode encoding issue
  • Loading branch information
feng-tao committed May 5, 2020
1 parent d2109ce commit 2018cc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions databuilder/loader/file_system_neo4j_csv_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,23 @@ def _get_writer(self,
return writer

LOGGER.info('Creating file for {}'.format(key))
file_out = open('{}/{}.csv'.format(dir_path, file_suffix), 'w')

def file_out_close():
# type: () -> None
LOGGER.info('Closing file IO {}'.format(file_out))
file_out.close()
self._closer.register(file_out_close)

if six.PY2:

file_out = open('{}/{}.csv'.format(dir_path, file_suffix), 'w')
writer = csv.DictWriter(file_out, fieldnames=csv_record_dict.keys(),
quoting=csv.QUOTE_NONNUMERIC, encoding='utf-8')
else:
file_out = open('{}/{}.csv'.format(dir_path, file_suffix), 'w', encoding='utf8')
writer = csv.DictWriter(file_out, fieldnames=csv_record_dict.keys(),
quoting=csv.QUOTE_NONNUMERIC)

def file_out_close():
# type: () -> None
LOGGER.info('Closing file IO {}'.format(file_out))
file_out.close()
self._closer.register(file_out_close)

writer.writeheader()
file_mapping[key] = writer

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages


__version__ = '2.5.11'
__version__ = '2.5.12'

requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file:
Expand Down

0 comments on commit 2018cc6

Please sign in to comment.