Skip to content

Commit 4f9fefc

Browse files
jcbozonierjreback
authored andcommitted
BUG: GH5398 Underscore support added for Google Analytics's new segments.
Added enhancement description for new segment support to v0.13 announcements. Found one last wrinkle in the format. Any of the valid characters can be anywhere in the string. I was too specific.
1 parent 05c9a74 commit 4f9fefc

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

doc/source/v0.13.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ Enhancements
643643
output datetime objects should be formatted. Datetimes encountered in the
644644
index, columns, and values will all have this formatting applied. (:issue:`4313`)
645645
- ``DataFrame.plot`` will scatter plot x versus y by passing ``kind='scatter'`` (:issue:`2215`)
646+
- Added support for Google Analytics v3 API segment IDs that also supports v2 IDs. (:issue:`5271`)
646647

647648
.. _whatsnew_0130.experimental:
648649

@@ -816,7 +817,6 @@ Experimental
816817
As of 10/10/13, there is a bug in Google's API preventing result sets
817818
from being larger than 100,000 rows. A patch is scheduled for the week of
818819
10/14/13.
819-
820820
.. _whatsnew_0130.refactoring:
821821

822822
Internal Refactoring

pandas/io/ga.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def format_query(ids, metrics, start_date, end_date=None, dimensions=None,
360360
[_maybe_add_arg(qry, n, d) for n, d in zip(names, lst)]
361361

362362
if isinstance(segment, compat.string_types):
363-
if re.match("^[a-zA-Z0-9]+\-*[a-zA-Z0-9]*$", segment):
363+
if re.match("^[a-zA-Z0-9\-\_]+$", segment):
364364
_maybe_add_arg(qry, 'segment', segment, 'gaid:')
365365
else:
366366
_maybe_add_arg(qry, 'segment', segment, 'dynamic::ga')

pandas/io/tests/test_ga.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ def test_v3_advanced_segment_common_format(self):
115115
assert query['segment'] == 'gaid::' + str(advanced_segment_id), "A string value with just letters and numbers should be formatted as an advanced segment."
116116

117117
def test_v3_advanced_segment_weird_format(self):
118-
advanced_segment_id = 'aZwqR234-s1'
118+
advanced_segment_id = '_aZwqR234-s1'
119119
query = ga.format_query('google_profile_id', ['visits'], '2013-09-01', segment=advanced_segment_id)
120120
assert query['segment'] == 'gaid::' + str(advanced_segment_id), "A string value with just letters, numbers, and hyphens should be formatted as an advanced segment."
121121

122+
def test_v3_advanced_segment_with_underscore_format(self):
123+
advanced_segment_id = 'aZwqR234_s1'
124+
query = ga.format_query('google_profile_id', ['visits'], '2013-09-01', segment=advanced_segment_id)
125+
assert query['segment'] == 'gaid::' + str(advanced_segment_id), "A string value with just letters, numbers, and underscores should be formatted as an advanced segment."
126+
127+
122128
@slow
123129
@with_connectivity_check("http://www.google.com")
124130
def test_segment(self):

0 commit comments

Comments
 (0)