Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
am-tropin committed Nov 15, 2023
1 parent c1837d1 commit e32f0b8
Show file tree
Hide file tree
Showing 9 changed files with 26,320 additions and 27 deletions.
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"id": "ef151508",
"metadata": {},
"outputs": [],
"source": []
"source": [
"APARTMENTS_FILE = \"poland_apartments_completed.csv\""
]
},
{
"cell_type": "code",
Expand All @@ -49,7 +51,7 @@
"outputs": [],
"source": [
"def load_data():\n",
" price_df4 = pd.read_csv(\"poland_apartments_completed.csv\")\n",
" price_df4 = pd.read_csv(APARTMENTS_FILE)\n",
" cat_features = ['city', 'district'] # 'floor', 'rooms'?\n",
" num_features = ['floor', 'rooms', 'sq', 'year', 'radius']\n",
" target = ['price']\n",
Expand Down Expand Up @@ -339,7 +341,8 @@
"source": [
"def check_city_district_radius_floor_rooms(city, district, radius, floor, rooms):\n",
" \n",
" price_df4 = pd.read_csv(\"poland_apartments_completed.csv\")\n",
"# price_df4 = pd.read_csv(APARTMENTS_FILE)\n",
" price_df4 = load_data()[0]\n",
" floor_values = list(set(price_df4['floor']))\n",
" rooms_values = list(set(price_df4['rooms']))\n",
" \n",
Expand Down
9 changes: 6 additions & 3 deletions app/functions/function_store.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"id": "ef151508",
"metadata": {},
"outputs": [],
"source": []
"source": [
"APARTMENTS_FILE = \"poland_apartments_completed.csv\""
]
},
{
"cell_type": "code",
Expand All @@ -49,7 +51,7 @@
"outputs": [],
"source": [
"def load_data():\n",
" price_df4 = pd.read_csv(\"poland_apartments_completed.csv\")\n",
" price_df4 = pd.read_csv(APARTMENTS_FILE)\n",
" cat_features = ['city', 'district'] # 'floor', 'rooms'?\n",
" num_features = ['floor', 'rooms', 'sq', 'year', 'radius']\n",
" target = ['price']\n",
Expand Down Expand Up @@ -339,7 +341,8 @@
"source": [
"def check_city_district_radius_floor_rooms(city, district, radius, floor, rooms):\n",
" \n",
" price_df4 = pd.read_csv(\"poland_apartments_completed.csv\")\n",
"# price_df4 = pd.read_csv(APARTMENTS_FILE)\n",
" price_df4 = load_data()[0]\n",
" floor_values = list(set(price_df4['floor']))\n",
" rooms_values = list(set(price_df4['rooms']))\n",
" \n",
Expand Down
7 changes: 4 additions & 3 deletions app/functions/function_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
# In[ ]:



APARTMENTS_FILE = "poland_apartments_completed.csv"


# In[ ]:


def load_data():
price_df4 = pd.read_csv("poland_apartments_completed.csv")
price_df4 = pd.read_csv(APARTMENTS_FILE)
cat_features = ['city', 'district'] # 'floor', 'rooms'?
num_features = ['floor', 'rooms', 'sq', 'year', 'radius']
target = ['price']
Expand Down Expand Up @@ -272,7 +272,8 @@ def experiment_initialization(experiment_name):

def check_city_district_radius_floor_rooms(city, district, radius, floor, rooms):

price_df4 = pd.read_csv("poland_apartments_completed.csv")
# price_df4 = pd.read_csv(APARTMENTS_FILE)
price_df4 = load_data()[0]
floor_values = list(set(price_df4['floor']))
rooms_values = list(set(price_df4['rooms']))

Expand Down
156 changes: 150 additions & 6 deletions app/tests/.ipynb_checkpoints/test_function_store-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"id": "c4bf99d5",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -42,17 +42,161 @@
"from functions.function_store import training_loop # depend on other functions\n",
"\n",
"# 3. For predicting by input data with the best model\n",
"from functions.function_store import check_city_district_radius_floor_rooms # depend on \"poland_apartments_completed.csv\"\n",
"from functions.function_store import input_to_df # depend on other functions\n",
"from functions.function_store import check_city_district_radius_floor_rooms, input_to_df # depend on other functions\n",
"from functions.function_store import select_best_model, main_predicting # depend on other functions\n",
"from functions.function_store import set_regressors, predict_by_input # don't depend on any functions\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "f9a4767d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(4315, 19)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"APARTMENTS_FILE = \"test_file1.csv\"\n",
"\n",
"# test_df = pd.read_csv('test_file.csv')\n",
"# # test_df.shape\n",
"\n",
"# test1_df = test_df.groupby('city').apply(lambda x: x.sample(frac=0.2)).reset_index(drop=True)\n",
"# # test1_df.shape\n",
"# test1_df.to_csv(\"test_file1.csv\")\n",
"\n",
"# https://stackoverflow.com/questions/22472213/python-random-selection-per-group"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "34e8e6d0",
"metadata": {},
"outputs": [],
"source": [
"# Creating a fixture that grabs a file before running a test\n",
"@pytest.fixture\n",
"def grab_test_file():\n",
" test_file = pd.read_csv(APARTMENTS_FILE)\n",
" return test_file\n",
"\n",
"# # Using the fixture in a test function\n",
"# def test_file_content(grab_test_file):\n",
"# assert grab_test_file.shape == (10, 5)\n",
"\n",
"# https://towardsdatascience.com/writing-better-code-through-testing-f3150abec6ca"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e65b3c8",
"metadata": {},
"outputs": [],
"source": [
"# def test_1_load_data(grab_test_file):\n",
"# assert grab_test_file.shape == (4315, 19)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed59d560",
"metadata": {},
"outputs": [],
"source": [
"def test_01_load_data():\n",
" assert load_data()[0].shape == (4315, 19)\n",
"\n",
"def test_11_load_data():\n",
" assert load_data()[1] == ['city', 'district']\n",
"\n",
"def test_21_load_data():\n",
" assert load_data()[2] == ['floor', 'rooms', 'sq', 'year', 'radius']\n",
" \n",
"def test_31_load_data():\n",
" assert load_data()[3] == ['price']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55c61f41",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4fb59c52",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa394a88",
"metadata": {},
"outputs": [],
"source": [
"def test_1_check_city_district_radius_floor_rooms():\n",
" assert check_city_district_radius_floor_rooms(\"Kraków\", \"Śródmieście\", 2, 3, 2) is False\n",
" \n",
" \n",
"# assert check_city_district_radius_floor_rooms(\"Warszawa\", \"Śródmieście\", 2, 3, 2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3419a26d",
"metadata": {},
"outputs": [],
"source": [
"# def check_city_district_radius_floor_rooms(city, district, radius, floor, rooms):\n",
" \n",
"# price_df4 = load_data()[0]\n",
"# floor_values = list(set(price_df4['floor']))\n",
"# rooms_values = list(set(price_df4['rooms']))\n",
" \n",
"# geo_df_for_check = price_df4.groupby(['city', 'district']).agg({'radius':['min','max']})\n",
" \n",
"# if (city, district) not in geo_df_for_check.index:\n",
"# print(\"Invalid city and/or district!\")\n",
"# return False\n",
"# else:\n",
"# min_radius = geo_df_for_check.loc[(city, district)][('radius', 'min')]\n",
"# max_radius = geo_df_for_check.loc[(city, district)][('radius', 'max')]\n",
"# if not (radius >= min_radius and radius <= max_radius):\n",
"# print(\"The radius must be between {0} and {1}\".format(round(min_radius, 2), round(max_radius, 2)))\n",
"# return False\n",
"# elif floor not in floor_values:\n",
"# print(\"The floor must be integer and between {0} and {1}\".format(floor_values.min(), floor_values.max()))\n",
"# return False\n",
"# elif rooms not in rooms_values:\n",
"# print(\"The rooms must be integer and between {0} and {1}\".format(rooms_values.min(), rooms_values.max()))\n",
"# return False\n",
"# else:\n",
"# return True"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ff642d5",
"metadata": {},
"outputs": [],
"source": []
},
Expand All @@ -79,7 +223,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "80cad016",
"id": "7a6256a5",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -115,7 +259,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "78174db7",
"id": "ad87745e",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit e32f0b8

Please sign in to comment.