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

[migration2viatot2.0]: Migrated Supermetrics #671

Closed

Conversation

fdelgadodyvenia
Copy link
Contributor

Summary

Supermetrics Migration

Importance

Migration to viadot 2.0

Checklist

This PR:

Copy link

@djagoda881 djagoda881 left a 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


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

class DatabricksCredentials(BaseModel):

Copy link
Contributor

Choose a reason for hiding this comment

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


@classmethod
def get_params_from_api_query(cls, url: str) -> Dict[str, Any]:
"""Returns parmeters from API query in a dictionary"""

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

Deletes table from AWS Glue database and related file from Amazon S3, if specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

return params_d

@classmethod
def from_url(cls, url: str, credentials: Dict[str, Any] = None):

Choose a reason for hiding this comment

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

Missing docstring

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Missing docstring

Copy link
Contributor

Choose a reason for hiding this comment

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

return obj

def to_json(self, timeout=(3.05, 60 * 30)) -> Dict[str, Any]:
"""Download query results to a dictionary.

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

Deletes table from AWS Glue database and related file from Amazon S3, if specified.

Copy link
Contributor

Choose a reason for hiding this comment

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


@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 ()"""

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

Deletes table from AWS Glue database and related file from Amazon S3, if specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

return columns

def _get_col_names(self) -> List[str]:
"""Returns list of columns names"""

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

Deletes table from AWS Glue database and related file from Amazon S3, if specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

if_empty (str, optional): What to do if query returned no data. Defaults to "warn".

Returns:
pd.DataFrame: the DataFrame containing query results

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

Copy link
Contributor

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",

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()

Copy link
Contributor

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!!!!!!!!!!!!!

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

Copy link
Contributor

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)

],
"max_rows": 1,
}
dict_ = s.query(google_ads_params).to_json()
Copy link

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?

Copy link
Contributor

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.

Copy link

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__?

Copy link
Contributor

Choose a reason for hiding this comment

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



def test__to_df():
# Create the query
Copy link

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.

Copy link
Contributor

Choose a reason for hiding this comment

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


def to_json(self, timeout=(3.05, 60 * 30)) -> Dict[str, Any]:
"""
Download query results to a dictionary.
Copy link

@eSlider eSlider Apr 20, 2023

Choose a reason for hiding this comment

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

  1. Maybe to_json means returning object himself transformed into JSON?
  2. Default timeout value is not human readable and can be transpiled to in the method description.

Copy link
Contributor

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".


Copy link

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

}


def test___get_col_names_other():
Copy link

@eSlider eSlider Apr 21, 2023

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

Copy link
Contributor

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


def query(self, params: Dict[str, Any]):
"""
Returns the query with the credentials info.
Copy link

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:

Copy link
Contributor

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

@trymzet
Copy link
Contributor

trymzet commented May 9, 2023

@fdelgadodyvenia Please keep 1 PR to 1 new feature (move the other connector to a separate PR)

Copy link
Contributor

@trymzet trymzet left a comment

Choose a reason for hiding this comment

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

Added my comments

from .base import Source

# Customed Errors!
class Source_NOK(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Exceptions in Python should be in CamelCase https://peps.python.org/pep-0008/#exception-names
  2. Pls add docstrings to explain what the exception is for

Copy link
Contributor

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

CHANGELOG.md Outdated Show resolved Hide resolved
"max_rows": 1,
}
df = s.query(google_ads_params).to_df()
assert df.count()[0] > 0
Copy link
Contributor

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

Copy link
Contributor

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

viadot/sources/velux_club.py Outdated Show resolved Hide resolved
viadot/sources/velux_club.py Outdated Show resolved Hide resolved
viadot/sources/velux_club.py Outdated Show resolved Hide resolved
viadot/sources/velux_club.py Outdated Show resolved Hide resolved
viadot/sources/velux_club.py Outdated Show resolved Hide resolved
@trymzet
Copy link
Contributor

trymzet commented May 25, 2023

@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?

@Diego-H-S
Copy link
Collaborator

Hey, another PR that must be reviewed.
This one with BigQuery and salesforce PRs is a very important PR to be reviewed to interact with Jackub as much as possible.

@trymzet
Copy link
Contributor

trymzet commented Sep 26, 2024

Closing since there is a newer PR for this #1054

@trymzet trymzet closed this Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants