Skip to content

Commit b9720b2

Browse files
authored
fix: consistent naming of positional arguments (#1310)
1 parent 98666e3 commit b9720b2

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

docs/backcompat.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Here are exceptions to our backwards compatibility policy:
9292
need to rethink Narwhals. However, we expect such radical changes to be exceedingly unlikely.
9393
- we may consider making some type hints more precise.
9494

95+
In general, decision are driven by use-cases, and we conduct a search of public GitHub repositories
96+
before making any change.
97+
9598
## Breaking changes carried out so far
9699

97100
### After `stable.v1`
@@ -120,19 +123,3 @@ Here are exceptions to our backwards compatibility policy:
120123
assert nw.Datetime("us") == nw.Datetime
121124
assert nw_v1.Datetime("us") == nw_v1.Datetime
122125
```
123-
124-
- The first argument to `from_native` has been renamed from `native_dataframe` to `native_object`:
125-
126-
```python
127-
# v1 syntax:
128-
nw.from_native(native_dataframe=df) # people tend to write this
129-
# main namespace syntax:
130-
nw.from_native(native_object=df)
131-
```
132-
133-
In practice, we recommend passing this argument positionally, and that will work consistently
134-
across namespaces:
135-
```python
136-
# Recommended
137-
nw.from_native(df)
138-
```

narwhals/stable/v1/__init__.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def _stableify(
577577

578578
@overload
579579
def from_native(
580-
native_dataframe: IntoDataFrameT | IntoSeriesT,
580+
native_object: IntoDataFrameT | IntoSeriesT,
581581
*,
582582
strict: Literal[False],
583583
eager_only: None = ...,
@@ -589,7 +589,7 @@ def from_native(
589589

590590
@overload
591591
def from_native(
592-
native_dataframe: IntoDataFrameT | IntoSeriesT,
592+
native_object: IntoDataFrameT | IntoSeriesT,
593593
*,
594594
strict: Literal[False],
595595
eager_only: Literal[True],
@@ -601,7 +601,7 @@ def from_native(
601601

602602
@overload
603603
def from_native(
604-
native_dataframe: IntoDataFrameT,
604+
native_object: IntoDataFrameT,
605605
*,
606606
strict: Literal[False],
607607
eager_only: None = ...,
@@ -613,7 +613,7 @@ def from_native(
613613

614614
@overload
615615
def from_native(
616-
native_dataframe: T,
616+
native_object: T,
617617
*,
618618
strict: Literal[False],
619619
eager_only: None = ...,
@@ -625,7 +625,7 @@ def from_native(
625625

626626
@overload
627627
def from_native(
628-
native_dataframe: IntoDataFrameT,
628+
native_object: IntoDataFrameT,
629629
*,
630630
strict: Literal[False],
631631
eager_only: Literal[True],
@@ -637,7 +637,7 @@ def from_native(
637637

638638
@overload
639639
def from_native(
640-
native_dataframe: T,
640+
native_object: T,
641641
*,
642642
strict: Literal[False],
643643
eager_only: Literal[True],
@@ -649,7 +649,7 @@ def from_native(
649649

650650
@overload
651651
def from_native(
652-
native_dataframe: IntoFrameT | IntoSeriesT,
652+
native_object: IntoFrameT | IntoSeriesT,
653653
*,
654654
strict: Literal[False],
655655
eager_only: None = ...,
@@ -661,7 +661,7 @@ def from_native(
661661

662662
@overload
663663
def from_native(
664-
native_dataframe: IntoSeriesT,
664+
native_object: IntoSeriesT,
665665
*,
666666
strict: Literal[False],
667667
eager_only: None = ...,
@@ -673,7 +673,7 @@ def from_native(
673673

674674
@overload
675675
def from_native(
676-
native_dataframe: IntoFrameT,
676+
native_object: IntoFrameT,
677677
*,
678678
strict: Literal[False],
679679
eager_only: None = ...,
@@ -685,7 +685,7 @@ def from_native(
685685

686686
@overload
687687
def from_native(
688-
native_dataframe: T,
688+
native_object: T,
689689
*,
690690
strict: Literal[False],
691691
eager_only: None = ...,
@@ -697,7 +697,7 @@ def from_native(
697697

698698
@overload
699699
def from_native(
700-
native_dataframe: IntoDataFrameT,
700+
native_object: IntoDataFrameT,
701701
*,
702702
strict: Literal[True] = ...,
703703
eager_only: None = ...,
@@ -713,7 +713,7 @@ def from_native(
713713

714714
@overload
715715
def from_native(
716-
native_dataframe: IntoDataFrameT,
716+
native_object: IntoDataFrameT,
717717
*,
718718
strict: Literal[True] = ...,
719719
eager_only: Literal[True],
@@ -729,7 +729,7 @@ def from_native(
729729

730730
@overload
731731
def from_native(
732-
native_dataframe: IntoFrameT | IntoSeriesT,
732+
native_object: IntoFrameT | IntoSeriesT,
733733
*,
734734
strict: Literal[True] = ...,
735735
eager_only: None = ...,
@@ -745,7 +745,7 @@ def from_native(
745745

746746
@overload
747747
def from_native(
748-
native_dataframe: IntoSeriesT | Any, # remain `Any` for downstream compatibility
748+
native_object: IntoSeriesT | Any, # remain `Any` for downstream compatibility
749749
*,
750750
strict: Literal[True] = ...,
751751
eager_only: None = ...,
@@ -761,7 +761,7 @@ def from_native(
761761

762762
@overload
763763
def from_native(
764-
native_dataframe: IntoFrameT,
764+
native_object: IntoFrameT,
765765
*,
766766
strict: Literal[True] = ...,
767767
eager_only: None = ...,
@@ -778,7 +778,7 @@ def from_native(
778778
# All params passed in as variables
779779
@overload
780780
def from_native(
781-
native_dataframe: Any,
781+
native_object: Any,
782782
*,
783783
strict: bool,
784784
eager_only: bool | None,
@@ -789,7 +789,7 @@ def from_native(
789789

790790

791791
def from_native(
792-
native_dataframe: Any,
792+
native_object: Any,
793793
*,
794794
strict: bool = True,
795795
eager_only: bool | None = None,
@@ -801,7 +801,7 @@ def from_native(
801801
Convert dataframe/series to Narwhals DataFrame, LazyFrame, or Series.
802802
803803
Arguments:
804-
native_dataframe: Raw object from user.
804+
native_object: Raw object from user.
805805
Depending on the other arguments, input object can be:
806806
807807
- pandas.DataFrame
@@ -825,12 +825,12 @@ def from_native(
825825
from narwhals.stable.v1 import dtypes
826826

827827
# Early returns
828-
if isinstance(native_dataframe, (DataFrame, LazyFrame)) and not series_only:
829-
return native_dataframe
830-
if isinstance(native_dataframe, Series) and (series_only or allow_series):
831-
return native_dataframe
828+
if isinstance(native_object, (DataFrame, LazyFrame)) and not series_only:
829+
return native_object
830+
if isinstance(native_object, Series) and (series_only or allow_series):
831+
return native_object
832832
result = _from_native_impl(
833-
native_dataframe,
833+
native_object,
834834
strict=strict,
835835
eager_only=eager_only,
836836
eager_or_interchange_only=eager_or_interchange_only,

tests/stable_api_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ def test_stable_api_docstrings() -> None:
8585
continue
8686
v1_doc = getattr(nw_v1, item).__doc__
8787
nw_doc = getattr(nw, item).__doc__
88-
if item == "from_native":
89-
v1_doc = v1_doc.replace("native_dataframe", "native_object")
9088
assert v1_doc == nw_doc
9189

9290

0 commit comments

Comments
 (0)