Skip to content

Commit 6c1ad8c

Browse files
committed
wip
1 parent 5f916d5 commit 6c1ad8c

File tree

2 files changed

+89
-92
lines changed

2 files changed

+89
-92
lines changed

narwhals/pandas_like/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def evaluate_into_expr(df: PandasDataFrame, into_expr: IntoExpr) -> list[PandasS
114114
"""
115115
Return list of raw columns.
116116
"""
117-
118117
expr = parse_into_expr(df._implementation, into_expr)
119118
return expr._call(df)
120119

t.py

+89-91
Original file line numberDiff line numberDiff line change
@@ -5,123 +5,121 @@
55

66
import narwhals as nw
77

8-
df_raw = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
9-
df = nw.DataFrame(df_raw, is_lazy=True)
10-
df_raw_2 = pd.DataFrame({"a": [1, 3], "c": [7, 9]})
11-
df2 = nw.DataFrame(df_raw_2, is_lazy=True)
8+
# df_raw = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
9+
# df = nw.DataFrame(df_raw, is_lazy=True)
10+
# df_raw_2 = pd.DataFrame({"a": [1, 3], "c": [7, 9]})
11+
# df2 = nw.DataFrame(df_raw_2, is_lazy=True)
1212

13-
result = df.sort("a", "b")
14-
print(nw.to_native(result))
13+
# result = df.sort("a", "b")
14+
# print(nw.to_native(result))
1515

16-
result = df.filter(nw.col("a") > 1)
17-
print(nw.to_native(result))
16+
# result = df.filter(nw.col("a") > 1)
17+
# print(nw.to_native(result))
1818

19-
result = df.with_columns(
20-
c=nw.col("a") + nw.col("b"),
21-
d=nw.col("a") - nw.col("a").mean(),
22-
)
23-
print(nw.to_native(result))
24-
result = df.with_columns(nw.all() * 2)
25-
print(nw.to_native(result))
19+
# result = df.with_columns(
20+
# c=nw.col("a") + nw.col("b"),
21+
# d=nw.col("a") - nw.col("a").mean(),
22+
# )
23+
# print(nw.to_native(result))
24+
# result = df.with_columns(nw.all() * 2)
25+
# print(nw.to_native(result))
2626

27-
result = df.with_columns(horizonal_sum=nw.sum_horizontal(nw.col("a"), nw.col("b")))
28-
print(nw.to_native(result))
29-
result = df.with_columns(horizonal_sum=nw.sum_horizontal("a", nw.col("b")))
30-
print(nw.to_native(result))
27+
# result = df.with_columns(horizonal_sum=nw.sum_horizontal(nw.col("a"), nw.col("b")))
28+
# print(nw.to_native(result))
29+
# result = df.with_columns(horizonal_sum=nw.sum_horizontal("a", nw.col("b")))
30+
# print(nw.to_native(result))
3131

3232

33-
result = df.select(nw.all().sum())
34-
print(nw.to_native(result))
35-
result = df.select(nw.col("a", "b") * 2)
36-
print(nw.to_native(result))
33+
# result = df.select(nw.all().sum())
34+
# print(nw.to_native(result))
35+
# result = df.select(nw.col("a", "b") * 2)
36+
# print(nw.to_native(result))
3737

38-
# # TODO!
39-
# # result = (
40-
# # df.collect()
41-
# # .group_by("b")
42-
# # .agg(
43-
# # nw.all().sum(),
44-
# # )
45-
# # )
46-
# # print(nw.to_native(result))
47-
48-
result = (
49-
df.collect()
50-
.group_by("b")
51-
.agg(
52-
nw.col("a").sum(),
53-
simple=nw.col("a").sum(),
54-
complex=(nw.col("a") + 1).sum(),
55-
other=nw.sum("a"),
56-
)
57-
)
58-
print(nw.to_native(result))
59-
print("multiple simple")
60-
result = (
61-
df.collect()
62-
.group_by("b")
63-
.agg(
64-
nw.col("a", "z").sum(),
65-
)
66-
)
67-
print(nw.to_native(result))
38+
# # # TODO!
39+
# # # result = (
40+
# # # df.collect()
41+
# # # .group_by("b")
42+
# # # .agg(
43+
# # # nw.all().sum(),
44+
# # # )
45+
# # # )
46+
# # # print(nw.to_native(result))
47+
48+
# result = (
49+
# df.collect()
50+
# .group_by("b")
51+
# .agg(
52+
# nw.col("a").sum(),
53+
# simple=nw.col("a").sum(),
54+
# complex=(nw.col("a") + 1).sum(),
55+
# other=nw.sum("a"),
56+
# )
57+
# )
58+
# print(nw.to_native(result))
59+
# print("multiple simple")
60+
# result = (
61+
# df.collect()
62+
# .group_by("b")
63+
# .agg(
64+
# nw.col("a", "z").sum(),
65+
# )
66+
# )
67+
# print(nw.to_native(result))
6868

69-
result = df.join(df2, left_on="a", right_on="a")
70-
print(nw.to_native(result))
69+
# result = df.join(df2, left_on="a", right_on="a")
70+
# print(nw.to_native(result))
7171

7272

73-
result = df.rename({"a": "a_new", "b": "b_new"})
74-
print(nw.to_native(result))
73+
# result = df.rename({"a": "a_new", "b": "b_new"})
74+
# print(nw.to_native(result))
7575

76-
result = df.collect().to_dict()
77-
print(result)
78-
print(polars.from_pandas(nw.to_native(df)).to_dict())
76+
# result = df.collect().to_dict()
77+
# print(result)
78+
# print(polars.from_pandas(nw.to_native(df)).to_dict())
7979

80-
result = df.collect().to_dict(as_series=False)
81-
print("this")
82-
print(result)
83-
print("that")
84-
print(polars.from_pandas(nw.to_native(df)).to_dict(as_series=False))
80+
# result = df.collect().to_dict(as_series=False)
81+
# print("this")
82+
# print(result)
83+
# print("that")
84+
# print(polars.from_pandas(nw.to_native(df)).to_dict(as_series=False))
8585

86-
agg = (nw.col("b") - nw.col("z").mean()).mean()
87-
print(nw.to_native(df.with_columns(d=agg)))
88-
result = df.group_by("a").agg(agg)
89-
print(nw.to_native(result))
86+
# agg = (nw.col("b") - nw.col("z").mean()).mean()
87+
# print(nw.to_native(df.with_columns(d=agg)))
88+
# result = df.group_by("a").agg(agg)
89+
# print(nw.to_native(result))
9090

91-
print(nw.col("a") + nw.col("b"))
92-
print(nw.col("a", "b").sum())
91+
# print(nw.col("a") + nw.col("b"))
92+
# print(nw.col("a", "b").sum())
9393

94-
result = df.select(nw.col("a", "b").sum())
95-
print(nw.to_native(result))
94+
# result = df.select(nw.col("a", "b").sum())
95+
# print(nw.to_native(result))
9696

97-
print(df.schema)
97+
# print(df.schema)
9898
# print(df.schema['a'].is_numeric())
9999

100-
# df_raw = pd.DataFrame({
101-
# "a": [1, 3, 2],
102-
# "b": [4., 4, 6],
103-
# 'c': ['a', 'b', 'c'],
104-
# 'd': [True, False, True],
105-
# })
106-
# df, pl = narwhals.to_polars_api(df_raw)
100+
df_raw = pd.DataFrame(
101+
{
102+
"a": [1, 3, 2],
103+
"b": [4.0, 4, 6],
104+
"c": ["a", "b", "c"],
105+
"d": [True, False, True],
106+
}
107+
)
108+
df = nw.DataFrame(df_raw)
107109
# print(df.schema)
108110
# print(df.schema['a'].is_numeric())
109111
# print(df.schema['b'].is_numeric())
110112
# print(df.schema['c'].is_numeric())
111113
# print(df.schema['d'].is_numeric())
112114

113-
# result = df.with_columns(nw.col('a').cast(pl.Float32))
115+
# result = df.with_columns(nw.col('a').cast(nw.Float32))
114116
# print(nw.to_native(result))
115-
# print(result._dataframe.dtypes)
117+
# print(result._dataframe._dataframe.dtypes)
116118

117119
# print(df.schema)
118-
# result = df.select([col for (col, dtype) in df.schema.items() if dtype == pl.Float64])
119-
# print(nw.to_native(result))
120-
# print(result._dataframe.dtypes)
121-
122-
# print(nw.all() + nw.col("a"))
123-
# result = df.select(nw.all() + nw.col("a"))
120+
# result = df.select([col for (col, dtype) in df.schema.items() if dtype == nw.Float64])
124121
# print(nw.to_native(result))
125-
# print(result._dataframe.dtypes)
122+
# print(result._dataframe._dataframe.dtypes)
126123

127-
# print(result.collect())
124+
result = df.select("a", "b").select(nw.all() + nw.col("a"))
125+
print(nw.to_native(result))

0 commit comments

Comments
 (0)