Skip to content

Commit

Permalink
Convert df values to strings. Closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
etrott committed May 9, 2018
1 parent aa15243 commit b1e68d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion df2gspread/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# @Last Modified time: 2016-03-08 12:36:30


version_info = ('1', '0', '2')
version_info = ('1', '0', '3')
__version__ = '.'.join(version_info[0:3]) # + '-' + version_info[3]
13 changes: 6 additions & 7 deletions df2gspread/df2gspread.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pass


def upload(df, gfile="/New Spreadsheet", wks_name=None, chunk_size=1000,
def upload(df, gfile="/New Spreadsheet", wks_name=None,
col_names=True, row_names=True, clean=True, credentials=None,
start_cell = 'A1', df_size = False, new_sheet_dimensions = (1000,100)):
'''
Expand All @@ -31,7 +31,6 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None, chunk_size=1000,
:param df: Pandas DataFrame
:param gfile: path to Google Spreadsheet or gspread ID
:param wks_name: worksheet name
:param chunk_size: size of chunk to upload
:param col_names: passing top row to column names for Pandas DataFrame
:param row_names: passing left column to row names for Pandas DataFrame
:param clean: clean all data in worksheet before uploading
Expand All @@ -50,7 +49,6 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None, chunk_size=1000,
:type df: class 'pandas.core.frame.DataFrame'
:type gfile: str
:type wks_name: str
:type chunk_size: int
:type col_names: bool
:type row_names: bool
:type clean: bool
Expand Down Expand Up @@ -124,19 +122,20 @@ def upload(df, gfile="/New Spreadsheet", wks_name=None, chunk_size=1000,
if col_names:
cell_list = wks.range('%s%s:%s%s' % (first_col, start_row, last_col, start_row))
for idx, cell in enumerate(cell_list):
o = df.columns.values[idx]
cell.value = o if not isinstance(o, np.integer) else int(o)
cell.value = df.columns.astype(str)[idx]
wks.update_cells(cell_list)

# Addition of row names
if row_names:
cell_list = wks.range('%s%s:%s%d' % (
start_col, first_row, start_col, last_idx))
for idx, cell in enumerate(cell_list):
o = df.index[idx]
cell.value = o if not isinstance(o, np.integer) else int(o)
cell.value = df.index.astype(str)[idx]
wks.update_cells(cell_list)


# convert df values to string
df = df.applymap(str)
# Addition of cell values
cell_list = wks.range('%s%s:%s%d' % (
first_col, first_row, last_col, last_idx))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_df2gspread.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_version_check():
# THIS NEEDS TO BE UPDATED EVERY TIME THE MAIN PACKAGE
# VERSION IS UPDATED!!!
######################################################
_v = '1.0.2'
_v = '1.0.3'

if _version.__version__ != _v:
raise SystemError('SYNC VERSION in tests/test_members.py')
Expand Down

0 comments on commit b1e68d7

Please sign in to comment.