Skip to content

Commit

Permalink
Merge pull request #66 from ParclLabs/logging
Browse files Browse the repository at this point in the history
Linting fix
  • Loading branch information
zhibindai26 authored Sep 6, 2024
2 parents 2d838c8 + ff3d840 commit 2de72f6
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Run Lint 🧹
run: |
set -e
pipenv run make lint
pipenv run make lint-check
- name: Run tests 🧪
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag_and_publish_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Run Lint
run: |
set -e
pipenv run make lint
pipenv run make lint-check
- name: Run tests
env:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v1.6.3
- Fix bug to enforce linting throughout the repository.
- Minor code improvements

### v1.6.2
- Fix bug where `limit` parameter was not being applied when `turbo_mode` was enabled.
- Update handingling of `limit` parameter. If the `limit` parameter is greater than maximum allowed limit on the particular endpoint, the `limit` will automatically default to the maximum allowed value instead of throwing an error.
Expand Down
372 changes: 186 additions & 186 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion parcllabs/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.6.2"
VERSION = "1.6.3"
7 changes: 3 additions & 4 deletions parcllabs/parcllabs_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Dict, Any, Optional

from parcllabs import api_base
from parcllabs.services.search import SearchMarkets
from parcllabs.services.parcllabs_service import ParclLabsService
from parcllabs.services.metrics.property_type_service import PropertyTypeService
from parcllabs.services.metrics.portfolio_size_service import PortfolioSizeService
from parcllabs.services.properties.property_events_service import PropertyEventsService
from parcllabs.services.properties.property_search import PropertySearch
from typing import Dict, Any, Optional


class ServiceGroup:
Expand All @@ -21,9 +22,7 @@ def add_service(
post_url: Optional[str] = None,
alias: Optional[str] = None,
):
service = service_class(
url=url, post_url=post_url, client=self._client
)
service = service_class(url=url, post_url=post_url, client=self._client)
setattr(self, name, service)
self._services[name] = service
if alias:
Expand Down
35 changes: 21 additions & 14 deletions parcllabs/services/parcllabs_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import pandas as pd
import requests
import json
import platform
from typing import Any, Mapping, Optional, List, Dict
from collections import deque
import json

import requests
from requests.exceptions import RequestException
from typing import Any, Mapping, Optional, List, Dict
from parcllabs.common import DELETE_FROM_OUTPUT, DEFAULT_LIMIT_SMALL, DEFAULT_LIMIT_LARGE
import platform
import pandas as pd

from parcllabs.common import (
DELETE_FROM_OUTPUT,
DEFAULT_LIMIT_SMALL,
DEFAULT_LIMIT_LARGE,
)
from parcllabs.exceptions import NotFoundError
from parcllabs.services.validators import Validators
from parcllabs.services.data_utils import safe_concat_and_format_dtypes
Expand All @@ -18,9 +23,7 @@ class ParclLabsService:
Base class for working with data from the Parcl Labs API.
"""

def __init__(
self, url: str, client: Any, post_url: str = None
) -> None:
def __init__(self, url: str, client: Any, post_url: str = None) -> None:
self.url = url
self.post_url = post_url
self.client = client
Expand Down Expand Up @@ -239,7 +242,7 @@ def _process_and_paginate_response(
response,
auto_paginate,
original_params,
data=None,
data=None,
referring_method: str = "get",
):

Expand All @@ -257,7 +260,9 @@ def _process_and_paginate_response(
while result["links"].get("next") is not None:
next_url = result["links"]["next"]
if referring_method == "post":
next_response = self._post(next_url, data=data, params=original_params)
next_response = self._post(
next_url, data=data, params=original_params
)
else:
next_response = self._get(next_url, params=original_params)
next_response.raise_for_status()
Expand Down Expand Up @@ -308,7 +313,8 @@ def retrieve(

return self._as_pd_dataframe(data_container)

def sanitize_output(self, data: Dict[str, Any]) -> Dict[str, Any]:
@staticmethod
def sanitize_output(data: Dict[str, Any]) -> Dict[str, Any]:
return {k: v for k, v in data.items() if k not in DELETE_FROM_OUTPUT}

def _as_pd_dataframe(self, data: List[Mapping[str, Any]]) -> pd.DataFrame:
Expand All @@ -325,7 +331,8 @@ def _as_pd_dataframe(self, data: List[Mapping[str, Any]]) -> pd.DataFrame:

return safe_concat_and_format_dtypes(data_container)

def error_handling(self, response: requests.Response) -> None:
@staticmethod
def error_handling(response: requests.Response) -> None:
try:
error_details = response.json()
error_message = error_details.get("detail", "No detail provided by API")
Expand All @@ -349,7 +356,7 @@ def error_handling(self, response: requests.Response) -> None:
raise requests.RequestException(msg)

@staticmethod
def _validate_limit(method, limit):
def _validate_limit(method: str, limit: int) -> int:
if method.upper() == "POST":
if limit > DEFAULT_LIMIT_LARGE:
print(
Expand Down
8 changes: 4 additions & 4 deletions parcllabs/services/properties/property_events_service.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections import deque
from typing import Any, Mapping, Optional, List
import pandas as pd
from concurrent.futures import ThreadPoolExecutor, as_completed

from alive_progress import alive_bar

from parcllabs.common import (
DEFAULT_LIMIT,
VALID_EVENT_TYPES,
VALID_ENTITY_NAMES,
MAX_POST_LIMIT,
Expand All @@ -12,10 +13,9 @@
safe_concat_and_format_dtypes,
)
from parcllabs.services.validators import Validators
from parcllabs.services.streaming.parcl_labs_streaming_service import (
from parcllabs.services.streaming.parcllabs_streaming_service import (
ParclLabsStreamingService,
)
from concurrent.futures import ThreadPoolExecutor, as_completed
from parcllabs.exceptions import (
NotFoundError,
) # Assuming this is the exception for a 404 error
Expand Down
8 changes: 5 additions & 3 deletions parcllabs/services/properties/property_search.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import List
from collections import deque

import pandas as pd
from alive_progress import alive_bar
from typing import List
from parcllabs.services.validators import Validators

from parcllabs.common import VALID_PROPERTY_TYPES_UNIT_SEARCH, VALID_ENTITY_NAMES
from parcllabs.services.streaming.parcl_labs_streaming_service import (
from parcllabs.services.validators import Validators
from parcllabs.services.streaming.parcllabs_streaming_service import (
ParclLabsStreamingService,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from parcllabs.services.parcllabs_service import ParclLabsService

import json
from collections import deque
from concurrent.futures import ThreadPoolExecutor, as_completed
import json

import pandas as pd

from parcllabs.services.parcllabs_service import ParclLabsService


class ParclLabsStreamingService(ParclLabsService):
def _convert_text_to_json(self, chunk):
Expand Down
4 changes: 1 addition & 3 deletions tests/test_parcl_labs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class MockClient:
@pytest.fixture
def parcl_labs_service():
client = MockClient()
return ParclLabsService(
url="https://api.example.com/{parcl_id}", client=client
)
return ParclLabsService(url="https://api.example.com/{parcl_id}", client=client)


def test_get_headers(parcl_labs_service):
Expand Down
14 changes: 10 additions & 4 deletions tests/test_price_feed_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from parcllabs.services.streaming.parcl_labs_streaming_service import (
from parcllabs.services.streaming.parcllabs_streaming_service import (
ParclLabsStreamingService,
)
import pytest
Expand Down Expand Up @@ -87,7 +87,9 @@ def test_make_request_http_error(self, mock_request, service):

def test_post(self, service):
with patch.object(service, "_make_request") as mock_make_request:
service._post("https://api.example.com/test", params={}, data={"data": "test"})
service._post(
"https://api.example.com/test", params={}, data={"data": "test"}
)
mock_make_request.assert_called_once_with(
"POST", "https://api.example.com/test", params={}, json={"data": "test"}
)
Expand Down Expand Up @@ -131,10 +133,14 @@ def test_process_and_paginate_response_post(self, mock_post, service):

mock_post.return_value = mock_next_response

result = service._process_and_paginate_response(mock_response, True, {}, {}, "post")
result = service._process_and_paginate_response(
mock_response, True, {}, {}, "post"
)
assert result["items"] == [1, 2, 3, 4]
assert service.client.estimated_session_credit_usage == 4
mock_post.assert_called_once_with("https://api.example.com/next", data={}, params={})
mock_post.assert_called_once_with(
"https://api.example.com/next", data={}, params={}
)

@patch("parcllabs.services.parcllabs_service.ParclLabsService._get")
def test_process_and_paginate_response_get(self, mock_get, service):
Expand Down

0 comments on commit 2de72f6

Please sign in to comment.