Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fixed a bug that all TIMESTAMP fileds become 00 secconds. #148

Merged
merged 3 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas_gbq/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def encode_chunk(dataframe):
csv_buffer = six.StringIO()
dataframe.to_csv(
csv_buffer, index=False, header=False, encoding='utf-8',
date_format='%Y-%m-%d %H:%M')
date_format='%Y-%m-%d %H:%M:%S.%f')

# Convert to a BytesIO buffer so that unicode text is properly handled.
# See: https://github.com/pydata/pandas-gbq/issues/106
Expand Down
23 changes: 23 additions & 0 deletions pandas_gbq/tests/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,29 @@ def test_upload_data_with_missing_schema_fields_raises_error(self):
private_key=self.credentials,
table_schema=test_schema)

def test_upload_data_with_timestamp(self):
test_id = "21"
test_size = 6
df = DataFrame(np.random.randn(test_size, 4), index=range(test_size),
columns=list('ABCD'))
df['times'] = np.datetime64('2018-03-13T05:40:45.348318Z')

gbq.to_gbq(
df, self.destination_table + test_id,
_get_project_id(),
private_key=self.credentials)

result_df = gbq.read_gbq("SELECT * FROM {0}".format(
self.destination_table + test_id),
project_id=_get_project_id(),
private_key=self.credentials)

assert len(result_df) == test_size

expected = df['times'].sort_values()
result = result_df['times'].sort_values()
tm.assert_numpy_array_equal(expected.values, result.values)

def test_list_dataset(self):
dataset_id = self.dataset_prefix + "1"
assert dataset_id in self.dataset.datasets()
Expand Down