This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
fix: fix as_dataframe
#91
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96a0109
chore: install pandas for unit tests
busunkim96 e6d04bc
fix: fix as_dataframe
busunkim96 7e0a8a0
docs: add note about proto-plus
busunkim96 48319f1
chore: fix lint in samples
busunkim96 2b01e13
chore: address review comments
busunkim96 f8d86ce
fix: use the pb nanoseconds representatin
busunkim96 d6d6ac0
chore: treat docs warnings as errors
busunkim96 586cc0d
chore: blacken
busunkim96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,16 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
try: | ||
import pandas | ||
except ImportError: | ||
HAVE_PANDAS = False | ||
else: | ||
HAVE_PANDAS = True # pragma: NO COVER | ||
|
||
import pandas | ||
import unittest | ||
|
||
from google.api import metric_pb2 | ||
from google.api import monitored_resource_pb2 | ||
from google.api_core import datetime_helpers | ||
from google.cloud import monitoring_v3 | ||
from google.cloud.monitoring_v3 import _dataframe | ||
|
||
|
||
PROJECT = "my-project" | ||
|
||
|
@@ -52,26 +53,26 @@ | |
|
||
|
||
def parse_timestamps(): | ||
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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤔 |
||
|
||
|
||
def generate_query_results(): | ||
from google.cloud.monitoring_v3 import types | ||
|
||
def P(timestamp, value): | ||
interval = types.TimeInterval() | ||
interval.start_time.FromJsonString(timestamp) | ||
interval.end_time.FromJsonString(timestamp) | ||
return types.Point(interval=interval, value={"double_value": value}) | ||
interval = monitoring_v3.TimeInterval() | ||
interval.start_time = datetime_helpers.from_rfc3339(timestamp).replace( | ||
tzinfo=None | ||
) | ||
interval.end_time = datetime_helpers.from_rfc3339(timestamp).replace( | ||
tzinfo=None | ||
) | ||
return monitoring_v3.Point(interval=interval, value={"double_value": value}) | ||
|
||
for metric_labels, resource_labels, value in zip( | ||
METRIC_LABELS, RESOURCE_LABELS, VALUES | ||
): | ||
yield types.TimeSeries( | ||
metric=types.Metric(type=METRIC_TYPE, labels=metric_labels), | ||
resource=types.MonitoredResource( | ||
yield monitoring_v3.TimeSeries( | ||
metric=metric_pb2.Metric(type=METRIC_TYPE, labels=metric_labels), | ||
resource=monitored_resource_pb2.MonitoredResource( | ||
type=RESOURCE_TYPE, labels=resource_labels | ||
), | ||
metric_kind=METRIC_KIND, | ||
|
@@ -80,12 +81,9 @@ def P(timestamp, value): | |
) | ||
|
||
|
||
@unittest.skipUnless(HAVE_PANDAS, "No pandas") | ||
class Test__build_dataframe(unittest.TestCase): | ||
def _call_fut(self, *args, **kwargs): | ||
from google.cloud.monitoring_v3._dataframe import _build_dataframe | ||
|
||
return _build_dataframe(*args, **kwargs) | ||
return _dataframe._build_dataframe(*args, **kwargs) | ||
|
||
def test_both_label_and_labels_illegal(self): | ||
with self.assertRaises(ValueError): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah what this seems to do is convert the time to just nanoseconds... https://proto-plus-python.readthedocs.io/en/latest/reference/datetime_helpers.html#proto.datetime_helpers.DatetimeWithNanoseconds