Skip to content

Commit 236fd00

Browse files
authored
Merge pull request #204 from behrica/tmd8.012
Tmd8.012
2 parents ce870a5 + 1f446e0 commit 236fd00

6 files changed

Lines changed: 58 additions & 14 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ pom.xml.asc
2424
.quarto
2525
.clay*
2626
.calva
27+
.vscode

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Change Log
2+
## unreleased
3+
4+
- upgraded to TMD 8.012 ([#203])(https://github.com/scicloj/tablecloth/issues/203)
25

36
## [7.042]
47

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{:extra-paths ["data"]
22
:deps {org.clojure/clojure {:mvn/version "1.12.2"}
3-
techascent/tech.ml.dataset {:mvn/version "7.067"}}
3+
techascent/tech.ml.dataset {:mvn/version "8.012"}}
44
:aliases {:dev {:extra-deps {org.scicloj/clay {:mvn/version "2-beta54"}
55
org.scicloj/note-to-test {:mvn/version "1-alpha7"}}}
66
:test {:extra-deps {org.scicloj/clay {:mvn/version "2-beta54"}

src/tablecloth/api.clj

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,31 @@ column-names function returns names according to columns-selector
15051505

15061506

15071507
(defn map-column->columns
1508+
"
1509+
The map-column->columns function transforms a dataset by expanding a column containing map values into
1510+
multiple new columns. Specifically, it takes a source dataset ds and a source column src-col within that dataset (which contains map values), and performs the following operations:
1511+
1512+
- Extracts the map data from src-col.
1513+
- Creates a new dataset from this map data, where each key in the maps becomes a column.
1514+
- Generates new column names by combining the name of src-col with each of the original map keys, using a dash (-) as a separator. The type (keyword, symbol, or string) of the new column names matches the type of src-col.
1515+
- Appends these new columns to the original dataset ds.
1516+
- Removes the original src-col from ds.
1517+
1518+
The result is a new dataset that includes all original columns (except src-col) and the newly expanded columns derived from the maps in src-col.
1519+
Parameters
1520+
1521+
1522+
'ds': The input dataset, expected to be a Tablecloth dataset or any dataset compatible with the functions used.
1523+
'src-col': The name (keyword, symbol, or string) of the source column in ds that contains map values.
1524+
1525+
Return Value
1526+
1527+
A new dataset with the following characteristics:
1528+
1529+
Contains all columns from the original dataset ds, except the src-col.
1530+
Includes new columns derived from the keys of the maps in src-col, with names formed by combining src-col and the map keys.
1531+
The new columns are appropriately named and typed, maintaining the type consistency with src-col.
1532+
"
15081533
([ds src-col]
15091534
(tablecloth.api.join-separate/map-column->columns ds src-col)))
15101535

@@ -2588,9 +2613,9 @@ column-names function returns names according to columns-selector
25882613

25892614
(defn update-columns
25902615
"Updates columns of a dataset.
2591-
2592-
Takes either a map of column name -> column update function (receiving a 'row')
2593-
or a column selector and a list of column update function, each taking a 'row' "
2616+
2617+
Takes either a map of column name -> column update function (receiving a 'row')
2618+
or a column selector and a list of column update function, each taking a 'row' "
25942619
([ds columns-map]
25952620
(tablecloth.api.columns/update-columns ds columns-map))
25962621
([ds columns-selector update-functions]

src/tablecloth/api/utils.clj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,11 @@ column-names function returns names according to columns-selector
215215

216216
(defn ^:deprecated write-nippy!
217217
[ds filename]
218-
(let [f (if (gzipped? filename)
219-
(tio/gzip-output-stream! filename)
220-
filename)]
221-
(tio/put-nippy! f ds)))
218+
(ds/write! ds filename))
222219

223220
(defn ^:deprecated read-nippy
224221
[filename]
225-
(let [f (if (gzipped? filename)
226-
(tio/gzip-input-stream filename)
227-
filename)]
228-
(tio/get-nippy f)))
222+
(ds/->dataset filename))
229223

230224
;; parallel concat
231225

test/tablecloth/api/dataset_test.clj

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,34 @@
7373
(fact (-> (api/dataset "DS.csv.gz")
7474
(api/dataset?))
7575
=> true)
76-
(fact (do (api/write-nippy! DS "DS.nippy.gz")
76+
(fact (do (api/write! DS "DS.nippy.gz")
7777
(.exists (io/file "DS.nippy.gz")))
7878
=> true)
79-
(fact (-> (api/read-nippy "DS.nippy.gz")
79+
(fact (do (api/write! DS "DS.nippy")
80+
(.exists (io/file "DS.nippy")))
81+
=> true)
82+
83+
(fact (do (api/write! DS "DS.nippy.gz")
84+
(.exists (io/file "DS.nippy.gz")))
85+
=> true)
86+
87+
(fact (do (api/write-nippy! DS "DS-1.nippy.gz")
88+
(.exists (io/file "DS-1.nippy.gz")))
89+
=> true)
90+
91+
(fact (do (api/write-nippy! DS "DS-1.nippy")
92+
(.exists (io/file "DS-1.nippy")))
93+
=> true)
94+
95+
96+
(fact (-> (api/dataset "DS.nippy.gz")
97+
(api/dataset?))
98+
=> true)
99+
(fact (-> (api/dataset "DS.nippy")
80100
(api/dataset?))
81101
=> true))
82102

103+
83104
(fact "dataset-shape"
84105
(fact (api/shape DS)
85106
=> [9 4])

0 commit comments

Comments
 (0)