-
Notifications
You must be signed in to change notification settings - Fork 40
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
[migration2viatot2.0]: Migrated Supermetrics #671
[migration2viatot2.0]: Migrated Supermetrics #671
Conversation
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.
PR Looks good but needs some changes in dostrings and adding some unit tests. Also missing is an entry in the CHANGELOG.md
file and __init___.py
in source folder.
from ..utils import handle_api_response | ||
from .base import Source | ||
|
||
|
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.
Add please credentials definitions using Pydantic as in the example below
viadot/viadot/sources/databricks.py
Line 22 in 9239fcb
class DatabricksCredentials(BaseModel): |
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.
viadot/sources/supermetrics.py
Outdated
|
||
@classmethod | ||
def get_params_from_api_query(cls, url: str) -> Dict[str, Any]: | ||
"""Returns parmeters from API query in a dictionary""" |
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.
I think we can standardize docstrings as in other sources
viadot/viadot/sources/redshift_spectrum.py
Line 109 in 9239fcb
Deletes table from AWS Glue database and related file from Amazon S3, if specified. |
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.
viadot/sources/supermetrics.py
Outdated
return params_d | ||
|
||
@classmethod | ||
def from_url(cls, url: str, credentials: Dict[str, Any] = None): |
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.
Missing docstring
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.
return df | ||
|
||
def query(self, params: Dict[str, Any]): | ||
self.query_params = params |
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.
Missing docstring
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.
viadot/sources/supermetrics.py
Outdated
return obj | ||
|
||
def to_json(self, timeout=(3.05, 60 * 30)) -> Dict[str, Any]: | ||
"""Download query results to a dictionary. |
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.
I think we can standardize docstrings as in other sources
viadot/viadot/sources/redshift_spectrum.py
Line 109 in 9239fcb
Deletes table from AWS Glue database and related file from Amazon S3, if specified. |
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.
viadot/sources/supermetrics.py
Outdated
|
||
@classmethod | ||
def _get_col_names_other(cls, response: dict) -> List[str]: | ||
"""Returns list of columns names (to Google Analytics use _get_col_names_google_analytics ()""" |
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.
I think we can standardize docstrings as in other sources
viadot/viadot/sources/redshift_spectrum.py
Line 109 in 9239fcb
Deletes table from AWS Glue database and related file from Amazon S3, if specified. |
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.
viadot/sources/supermetrics.py
Outdated
return columns | ||
|
||
def _get_col_names(self) -> List[str]: | ||
"""Returns list of columns names""" |
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.
I think we can standardize docstrings as in other sources
viadot/viadot/sources/redshift_spectrum.py
Line 109 in 9239fcb
Deletes table from AWS Glue database and related file from Amazon S3, if specified. |
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.
viadot/sources/supermetrics.py
Outdated
if_empty (str, optional): What to do if query returned no data. Defaults to "warn". | ||
|
||
Returns: | ||
pd.DataFrame: the DataFrame containing query results |
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.
Missing dot .
and it starts with a lowercase letter
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.
assert columns == [ | ||
"Date", | ||
"View", | ||
"M-site_TOTAL: Bounces Landing", |
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.
I think you can add some more unit tests for functions like to_json()
, _get_col_names_other()
, to_df()
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.
viadot/config.py
Outdated
@@ -64,7 +64,8 @@ def get_source_config(key, config=CONFIG): | |||
if source_configs is not None: | |||
for source_config in source_configs: | |||
if key in source_config.keys(): | |||
return source_configs[source_configs.index(source_config)][key] | |||
# return source_configs[source_configs.index(source_config)][key] OBS!!!!!!!!!!!!! |
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.
Please add this to CHANGELOG.md
with issue number
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.
Also add/fix a test (in test_config.py
)
tests/unit/test_supermetrics.py
Outdated
], | ||
"max_rows": 1, | ||
} | ||
dict_ = s.query(google_ads_params).to_json() |
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.
Is adding a dash or sub-dash at the end conventional?
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.
dash added to distinguish python "dict" from our variable.
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.
@burzekj, the dict contains supermetrics
, whould it not be better to use the supermetrics
for the naming the dict? Otherways, if we need some improvement on the test function, an we get another dict_
, should it be named as dict__
?
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.
Name dict_ changed
✅ [migration2viatot2.0]: Migrated Supermetrics
tests/unit/test_supermetrics.py
Outdated
|
||
|
||
def test__to_df(): | ||
# Create the query |
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.
It is often repeated about query creation, although not everywhere, but it is better to describe what is going to be tested in the function annotation.
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.
viadot/sources/supermetrics.py
Outdated
|
||
def to_json(self, timeout=(3.05, 60 * 30)) -> Dict[str, Any]: | ||
""" | ||
Download query results to a dictionary. |
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.
- Maybe
to_json
means returning object himself transformed into JSON? - Default timeout value is not human readable and can be transpiled to in the method description.
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.
Args: | ||
if_empty (str, optional): What to do if query returned no data. Defaults to "warn". | ||
|
||
|
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.
At start, in the annotations(docstring), there were no spaces between text and end, then later they appeared, but one at the end. Now there are two. Should we pass to one format?
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.
tests/unit/test_supermetrics.py
Outdated
} | ||
|
||
|
||
def test___get_col_names_other(): |
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.
Function naming can be more human readable:
test get column names other
vs. test getting other column names
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.
functions names depends on source functions.
Added comments to be more human readable.
✅ Added changes to supermetrics source/test
viadot/sources/supermetrics.py
Outdated
|
||
def query(self, params: Dict[str, Any]): | ||
""" | ||
Returns the query with the credentials info. |
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.
The name of the function/method should describe what it does, for example, "Query the database using parameters." Then it should describe what parameters can be set and which of them are the default parameters. As example - api_key
parameter is missed in the description.
Returned values should be described on bottom of docsting, like with Args:
, but Returns:
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.
At this point its impossible to change the name of the functions - function called in other files.
Added docstring
✅ Added changes to supermetrics source/test
@fdelgadodyvenia Please keep 1 PR to 1 new feature (move the other connector to a separate PR) |
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.
Added my comments
viadot/sources/velux_club.py
Outdated
from .base import Source | ||
|
||
# Customed Errors! | ||
class Source_NOK(Exception): |
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.
- Exceptions in Python should be in CamelCase https://peps.python.org/pep-0008/#exception-names
- Pls add docstrings to explain what the exception is for
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.
velux-club removed from this PR
[Supermetrics]: Removed files from
"max_rows": 1, | ||
} | ||
df = s.query(google_ads_params).to_df() | ||
assert df.count()[0] > 0 |
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.
if you want to check the number of rows, you can just do assert len(df) == 1
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.
Changed the assert of the function output
[supermetrics-migration]: Done Pull Request Corrections
…yvenia/viadot into supermetrics_migration
@fdelgadodyvenia / @burzekj I see you're adding commits but not replying in conversations, can you pls make sure to answer each comment and point to relevant commit/place in commit so reviewers can verify and resolve conversations 1 by 1? |
Hey, another PR that must be reviewed. |
Closing since there is a newer PR for this #1054 |
Summary
Supermetrics Migration
Importance
Migration to viadot 2.0
Checklist
This PR:
Config.py/get_source_config within Viadot2 possible bug #670