Skip to content

Commit

Permalink
refactor[python]: Some minor stuff (#4704)
Browse files Browse the repository at this point in the history
* Remove empty init methods
* Make LDF classmethods private
* Add scan_ndjson to docs
  • Loading branch information
stinodego committed Sep 3, 2022
1 parent 8db19b8 commit 6576807
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions py-polars/docs/source/reference/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ JSON
:toctree: api/

read_json
scan_ndjson
DataFrame.write_json

AVRO
Expand Down
3 changes: 1 addition & 2 deletions py-polars/polars/internals/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def wrap_expr(pyexpr: PyExpr) -> Expr:
class Expr:
"""Expressions that can be used in various contexts."""

def __init__(self) -> None:
self._pyexpr: PyExpr # pragma: no cover
_pyexpr: PyExpr

@classmethod
def _from_pyexpr(cls, pyexpr: PyExpr) -> Expr:
Expand Down
12 changes: 7 additions & 5 deletions py-polars/polars/internals/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _from_pyldf(cls: type[LDF], ldf: PyLazyFrame) -> LDF:
return self

@classmethod
def scan_csv(
def _scan_csv(
cls: type[LDF],
file: str,
has_header: bool = True,
Expand Down Expand Up @@ -143,7 +143,7 @@ def scan_csv(
return self

@classmethod
def scan_parquet(
def _scan_parquet(
cls: type[LDF],
file: str,
n_rows: int | None = None,
Expand Down Expand Up @@ -187,7 +187,7 @@ def scan_parquet(
return self

@classmethod
def scan_ipc(
def _scan_ipc(
cls: type[LDF],
file: str | Path,
n_rows: int | None = None,
Expand All @@ -201,9 +201,11 @@ def scan_ipc(
"""
Lazily read from an Arrow IPC (Feather v2) file.
Use ``pl.scan_ipc`` to dispatch to this method.
See Also
--------
scan_parquet, scan_csv
polars.io.scan_ipc
"""
if isinstance(file, (str, Path)):
Expand All @@ -230,7 +232,7 @@ def scan_ipc(
return self

@classmethod
def scan_ndjson(
def _scan_ndjson(
cls: type[LDF],
file: str,
infer_schema_length: int | None = None,
Expand Down
8 changes: 4 additions & 4 deletions py-polars/polars/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def scan_csv(
if isinstance(file, (str, Path)):
file = format_path(file)

return LazyFrame.scan_csv(
return LazyFrame._scan_csv(
file=file,
has_header=has_header,
sep=sep,
Expand Down Expand Up @@ -631,7 +631,7 @@ def scan_ipc(
Only uncompressed IPC files can be memory mapped.
"""
return LazyFrame.scan_ipc(
return LazyFrame._scan_ipc(
file=file,
n_rows=n_rows,
cache=cache,
Expand Down Expand Up @@ -691,7 +691,7 @@ def scan_parquet(
if isinstance(file, (str, Path)):
file = format_path(file)

return LazyFrame.scan_parquet(
return LazyFrame._scan_parquet(
file=file,
n_rows=n_rows,
cache=cache,
Expand Down Expand Up @@ -744,7 +744,7 @@ def scan_ndjson(
if isinstance(file, (str, Path)):
file = format_path(file)

return LazyFrame.scan_ndjson(
return LazyFrame._scan_ndjson(
file=file,
infer_schema_length=infer_schema_length,
batch_size=batch_size,
Expand Down
3 changes: 0 additions & 3 deletions py-polars/polars/string_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class StringCache:
"""

def __init__(self) -> None:
pass

def __enter__(self) -> StringCache:
self._already_enabled = _using_string_cache()
if not self._already_enabled:
Expand Down
3 changes: 0 additions & 3 deletions py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,6 @@ def test_hashing_on_python_objects() -> None:
df = pl.DataFrame({"a": [1, 1, 3, 4], "b": [1, 1, 2, 2]})

class Foo:
def __init__(self) -> None:
pass

def __hash__(self) -> int:
return 0

Expand Down

0 comments on commit 6576807

Please sign in to comment.