Skip to content

Commit

Permalink
Merge pull request #423 from open-contracting/no-pandas
Browse files Browse the repository at this point in the history
chore: Remove pandas
  • Loading branch information
jpmckinney authored Oct 2, 2024
2 parents e174d64 + 59284f0 commit 55ba005
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
47 changes: 29 additions & 18 deletions app/routers/downloads.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import csv
import io
import zipfile
from typing import Any

import pandas as pd
from fastapi import APIRouter, Depends, Response
from reportlab.lib.pagesizes import letter
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer
Expand Down Expand Up @@ -142,25 +142,36 @@ async def export_applications(
) -> Response:
stream = io.StringIO()

pd.DataFrame(
writer = csv.writer(stream)
writer.writerow(
[
{
_("Legal Name", lang): application.borrower.legal_name,
_("National Tax ID", lang): application.borrower.legal_identifier,
_("Email Address", lang): application.primary_email,
_("Buyer Name", lang): application.award.buyer_name,
_("Award Value Currency & Amount", lang): application.award.award_amount,
_("Amount requested", lang): application.amount_requested,
_("Submission Date", lang): application.borrower_submitted_at,
_("Stage", lang): _(application.status, lang),
}
for application in (
models.Application.submitted_search(
session, lender_id=user.lender_id, sort_field="application.borrower_submitted_at", sort_order="asc"
)
)
_("Legal Name", lang),
_("National Tax ID", lang),
_("Email Address", lang),
_("Buyer Name", lang),
_("Award Value Currency & Amount", lang),
_("Amount requested", lang),
_("Submission Date", lang),
_("Stage", lang),
]
)
writer.writerows(
[
application.borrower.legal_name,
application.borrower.legal_identifier,
application.primary_email,
application.award.buyer_name,
application.award.award_amount,
application.amount_requested,
application.borrower_submitted_at,
_(application.status, lang),
]
).to_csv(stream, index=False, encoding="utf-8")
for application in (
models.Application.submitted_search(
session, lender_id=user.lender_id, sort_field="application.borrower_submitted_at", sort_order="asc"
)
)
)

return Response(
content=stream.getvalue(),
Expand Down
1 change: 0 additions & 1 deletion app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class Settings(BaseSettings):
sentry_sdk.init(
dsn=app_settings.sentry_dsn,
before_send=sentry_filter_transactions,
# Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
traces_sample_rate=1.0,
# FastAPI uses 400 for request validation errors, which shouldn't occur unless the frontend is misimplemented.
integrations=[
Expand Down
1 change: 0 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ minify-html
mypy-boto3-cognito-idp
mypy-boto3-ses
orjson
pandas
pydantic
pydantic-settings
pyjwt[crypto]
Expand Down
12 changes: 1 addition & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,8 @@ mypy-boto3-cognito-idp==1.29.0
# via -r requirements.in
mypy-boto3-ses==1.29.0
# via -r requirements.in
numpy==1.26.0
# via pandas
orjson==3.10.7
# via -r requirements.in
pandas==2.2.2
# via -r requirements.in
pillow==10.3.0
# via reportlab
psycopg2==2.9.6
Expand All @@ -102,15 +98,11 @@ pygments==2.18.0
pyjwt==2.8.0
# via -r requirements.in
python-dateutil==2.8.2
# via
# botocore
# pandas
# via botocore
python-dotenv==1.0.0
# via pydantic-settings
python-multipart==0.0.7
# via -r requirements.in
pytz==2023.3
# via pandas
reportlab==4.0.4
# via -r requirements.in
requests==2.32.3
Expand Down Expand Up @@ -155,8 +147,6 @@ typing-extensions==4.8.0
# pydantic-core
# sqlalchemy
# typer
tzdata==2023.3
# via pandas
urllib3==1.26.19
# via
# botocore
Expand Down
16 changes: 1 addition & 15 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,11 @@ mypy-boto3-ses==1.29.0
mypy-extensions==1.0.0
# via mypy
numpy==1.26.0
# via
# -r requirements.txt
# pandas
# pandas-stubs
# via pandas-stubs
orjson==3.10.7
# via -r requirements.txt
packaging==23.1
# via pytest
pandas==2.2.2
# via -r requirements.txt
pandas-stubs==2.2.2.240807
# via -r requirements_dev.in
pillow==10.3.0
Expand Down Expand Up @@ -185,17 +180,12 @@ python-dateutil==2.8.2
# -r requirements.txt
# botocore
# moto
# pandas
python-dotenv==1.0.0
# via
# -r requirements.txt
# pydantic-settings
python-multipart==0.0.7
# via -r requirements.txt
pytz==2023.3
# via
# -r requirements.txt
# pandas
pyyaml==6.0.2
# via responses
reportlab==4.0.4
Expand Down Expand Up @@ -277,10 +267,6 @@ typing-extensions==4.8.0
# sqlalchemy
# sqlalchemy2-stubs
# typer
tzdata==2023.3
# via
# -r requirements.txt
# pandas
urllib3==1.26.19
# via
# -r requirements.txt
Expand Down
3 changes: 1 addition & 2 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

@pytest.mark.skipif("CI" not in os.environ, reason="skipping slow test in development")
def test_valid_html(tmp_path):
files = (pathlib.Path(BASEDIR).parent / "email_templates").glob("*")
for file in files:
for file in (pathlib.Path(BASEDIR).parent / "email_templates").glob("*"):
(tmp_path / file.name).write_text(re.sub(r"{{[^}]+}}", "http://host", file.read_text()))

for path, report in ValidatorInterface().validate([str(path) for path in tmp_path.glob("*")]).registry.items():
Expand Down

0 comments on commit 55ba005

Please sign in to comment.