Skip to content

Commit

Permalink
fix(docs): improved documentation for check_csv method
Browse files Browse the repository at this point in the history
  • Loading branch information
MCatherine1994 committed Feb 2, 2025
1 parent 1c282ba commit 2037e7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Catherine Meng, Jessie Zhang, Zheng He
## Functions

- **`check_csv`**
Check if the given file is a CSV file by its extension.
Check if the given file has a CSV file extension and whether it can be read by the pandas library.
- **`missing_value_summary`**
This function is to provide a summary of missing values in the dataset.
- **`get_summary_statistics`**
Expand All @@ -45,9 +45,9 @@ from pyeda31.data_summary import get_summary_statistics
```python
data_file_path = "docs/sample_data.csv" # path to your data file
if not check_csv(data_file_path):
raise TypeError("The given file is not in CSV format. Please check your data file.")
raise TypeError("The given file either does not have a CSV file extension or cannot be read by the pandas library. Please check the printed error message for more details.")
```
#### Check if the data file has any missing values
#### Check if the data file has a CSV file extension and whether it can be read by the pandas library
```python
df = pd.read_csv(data_file_path)

Expand Down
4 changes: 2 additions & 2 deletions docs/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"source": [
"## Check if the Data File is in CSV Format\n",
"\n",
"Before performing any analysis, it is crucial to validate whether the given file is in the correct CSV format. You can verify this using the `check_csv` method. If the file is not in CSV format, an error message will be raised to notify the user."
"Before performing any analysis, it is crucial to validate whether the given file has a CSV file extension and whether it can be read by the pandas library. You can verify this using the `check_csv` method. If the file is not in CSV format, an error message will be printed to notify the user."
]
},
{
Expand All @@ -73,7 +73,7 @@
"outputs": [],
"source": [
"if not check_csv(file_name):\n",
" raise TypeError(\"The given file is not in CSV format. Please check your data file.\")"
" raise TypeError(\"The given file either does not have a CSV file extension or cannot be read by the pandas library. Please check the printed error message for more details.\")"
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions src/pyeda31/check_csv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd

def check_csv(file_path):
"""Check if the given file is a CSV file by its extension.
"""Check if the given file has a CSV file extension and whether it can be read by the pandas library.
Parameters
----------
Expand All @@ -11,12 +11,16 @@ def check_csv(file_path):
Returns
-------
bool
True if the file is a CSV file, False otherwise.
True if the file has a CSV extension and can be read by the pandas library.
False otherwise (e.g., incorrect file extension or read error).
Examples
--------
>>> from pyeda31.check_csv import check_csv
>>> check_csv("../data/raw/data.csv")
True
>>> check_csv("../data/raw/data.txt")
False
"""
# Check if file extension is .csv
if not file_path.endswith(".csv"):
Expand Down

0 comments on commit 2037e7e

Please sign in to comment.