Skip to content

Commit

Permalink
fix: fix duplocations on params given (#100)
Browse files Browse the repository at this point in the history
* fix: fix duplocations on params given

* fix: fix nrows and skipfooter compatibilities
  • Loading branch information
Sanix-Darker authored Mar 4, 2022
1 parent 81ded25 commit 1c25c92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions peakina/readers/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ def read_csv(
The read_csv method is able to make a preview by reading on chunks
"""
if preview_nrows is not None or preview_offset:
if (skipfooter := kwargs.pop("skipfooter", None)) is None:
skipfooter = 0

# In case we don't have the native nrows given in kwargs, we're going
# to use the provided preview_nrows
if (nrows := kwargs.get("nrows")) is None:
# and skipfooter should be equal to 0 because of this:
# cf : https://github.com/pandas-dev/pandas/blob/31c553f1e599e2695a33236e02511c2841ac9aa0/pandas/io/parsers/readers.py#L2209
if (nrows := kwargs.pop("nrows", None)) is None and skipfooter == 0:
nrows = preview_nrows

# In case we don't have the native skiprows given in kwargs,
# we're going to use the provided preview_offset as range(1, preview_offset + 1)
if (skiprows := kwargs.get("skiprows")) is None:
if (skiprows := kwargs.pop("skiprows", None)) is None:
skiprows = range(1, preview_offset + 1)

chunks = pd.read_csv(
Expand All @@ -44,6 +48,7 @@ def read_csv(
**kwargs,
# keep the first row 0 (as the header) and then skip everything else up to row `preview_offset`
skiprows=skiprows,
skipfooter=skipfooter,
nrows=nrows,
)
# if the chunksize is not in kwargs, we want to return the iterator
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "peakina"
version = "0.7.7"
version = "0.7.8"
description = "pandas readers on steroids (remote files, glob patterns, cache, etc.)"
authors = ["Toucan Toco <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 1c25c92

Please sign in to comment.