Isongzhe commited on
Commit
5aaeaea
·
verified ·
1 Parent(s): a26ab21

Fix usage examples: polars hf bug workaround, robust pyarrow glob

Browse files
Files changed (1) hide show
  1. README.md +29 -13
README.md CHANGED
@@ -57,13 +57,31 @@ Each record is one observation of one convective system (feature) at one 3-hourl
57
 
58
  Query directly from the Hub without downloading everything.
59
 
60
- Polars (lazy scan with predicate pushdown):
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  ```python
63
  import polars as pl
 
 
 
 
 
 
64
 
65
  df = (
66
- pl.scan_parquet("hf://datasets/NTU-CompHydroMet-Lab/ISCCP-H-CT/data/*.parquet")
67
  .filter(
68
  (pl.col("year").is_between(2010, 2016))
69
  & (pl.col("minTB_feature") < 220)
@@ -75,26 +93,24 @@ df = (
75
  )
76
  ```
77
 
78
- DuckDB (SQL):
 
 
 
79
 
80
- ```sql
81
- SELECT year, COUNT(*) AS n_obs, COUNT(DISTINCT global_cell_id) AS n_cells
82
- FROM 'hf://datasets/NTU-CompHydroMet-Lab/ISCCP-H-CT/data/*.parquet'
83
- GROUP BY year ORDER BY year;
84
  ```
85
 
86
- Download a single year:
87
 
88
  ```bash
89
- hf download NTU-CompHydroMet-Lab/ISCCP-H-CT data/ISCCP-H_CT_2016.parquet --repo-type dataset --local-dir .
90
  ```
91
 
92
- Pandas (single year):
93
-
94
  ```python
95
- import pandas as pd
96
 
97
- df = pd.read_parquet("hf://datasets/NTU-CompHydroMet-Lab/ISCCP-H-CT/data/ISCCP-H_CT_2016.parquet")
98
  ```
99
 
100
  ## Data Schema
 
57
 
58
  Query directly from the Hub without downloading everything.
59
 
60
+ DuckDB (SQL over all years):
61
+
62
+ ```python
63
+ import duckdb
64
+
65
+ duckdb.sql("""
66
+ SELECT year, COUNT(*) AS n_obs, COUNT(DISTINCT global_cell_id) AS n_cells
67
+ FROM 'hf://datasets/NTU-CompHydroMet-Lab/ISCCP-H-CT/data/*.parquet'
68
+ GROUP BY year ORDER BY year
69
+ """).show()
70
+ ```
71
+
72
+ Polars (lazy, with predicate pushdown). Note: Polars' native `hf://` scanner currently fails on namespaced repos ("url-encoded slash" error, upstream Polars bug), so route through `HfFileSystem` and PyArrow:
73
 
74
  ```python
75
  import polars as pl
76
+ import pyarrow.dataset as ds
77
+ from huggingface_hub import HfFileSystem
78
+
79
+ fs = HfFileSystem()
80
+ files = fs.glob("datasets/NTU-CompHydroMet-Lab/ISCCP-H-CT/data/*.parquet")
81
+ dataset = ds.dataset(files, filesystem=fs, format="parquet")
82
 
83
  df = (
84
+ pl.scan_pyarrow_dataset(dataset)
85
  .filter(
86
  (pl.col("year").is_between(2010, 2016))
87
  & (pl.col("minTB_feature") < 220)
 
93
  )
94
  ```
95
 
96
+ Pandas (single year):
97
+
98
+ ```python
99
+ import pandas as pd
100
 
101
+ df = pd.read_parquet("hf://datasets/NTU-CompHydroMet-Lab/ISCCP-H-CT/data/ISCCP-H_CT_2016.parquet")
 
 
 
102
  ```
103
 
104
+ For repeated analysis, download once and read locally (fastest):
105
 
106
  ```bash
107
+ hf download NTU-CompHydroMet-Lab/ISCCP-H-CT --repo-type dataset --include "data/*.parquet" --local-dir isccp_h_ct
108
  ```
109
 
 
 
110
  ```python
111
+ import polars as pl
112
 
113
+ df = pl.scan_parquet("isccp_h_ct/data/*.parquet") # all 35 years as one table
114
  ```
115
 
116
  ## Data Schema