Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

fix: fix as_dataframe #91

Merged
merged 8 commits into from Mar 12, 2021
Merged

fix: fix as_dataframe #91

merged 8 commits into from Mar 12, 2021

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Mar 5, 2021

The dataframe helper methods were being skipped because pandas was not installed in the unit test session. This re-enables those tests and makes the minimal number of fixes to get the unit tests passing again.

TODOs:

Fixes #90 馃

Simple example:

import datetime

from google.cloud import monitoring_v3
from google.cloud.monitoring_v3.query import Query
import pandas

# TODO: Change these to the desired project and metric_type
project_name = "my-project"
metric_type = "storage.googleapis.com/storage/object_count"

client = monitoring_v3.MetricServiceClient()

query = Query(client, project_name, metric_type=metric_type, end_time=None, days=7,)

df = query.as_dataframe()
print(df[:3])

@product-auto-label product-auto-label bot added the api: monitoring Issues related to the googleapis/python-monitoring API. label Mar 5, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 5, 2021
@busunkim96 busunkim96 requested review from arithmetic1728, parthea and software-dov and removed request for arithmetic1728 March 5, 2021 20:10
@@ -94,9 +99,7 @@ def _build_dataframe(time_series_iterable, label=None, labels=None): # pragma:
for time_series in time_series_iterable:
pandas_series = pandas.Series(
data=[_extract_value(point.value) for point in time_series.points],
index=[
point.interval.end_time.ToNanoseconds() for point in time_series.points
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from google.api_core import datetime_helpers

return [datetime_helpers.from_rfc3339(t).replace(tzinfo=None) for t in TIMESTAMPS]
return [pandas.Timestamp(t) for t in TIMESTAMPS]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pandas seems to have its own timestamp type (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timestamp.html), so I'm not sure how these tests used to work 馃

Copy link
Contributor

@parthea parthea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one minor observation.

synth.py Outdated Show resolved Hide resolved
@busunkim96 busunkim96 marked this pull request as ready for review March 12, 2021 00:33
@busunkim96 busunkim96 requested review from a team as code owners March 12, 2021 00:33
@busunkim96 busunkim96 requested review from tmatsuo and removed request for a team March 12, 2021 00:33
@busunkim96 busunkim96 merged commit f135202 into master Mar 12, 2021
@busunkim96 busunkim96 deleted the fix-datatframe branch March 12, 2021 00:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: monitoring Issues related to the googleapis/python-monitoring API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError: 'WhichOneof' while converting time series data to dataframe
2 participants