Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table Dialect Spec #697

Closed
roll opened this issue Jul 27, 2020 · 7 comments · Fixed by frictionlessdata/datapackage-v2-draft#41
Closed

Table Dialect Spec #697

roll opened this issue Jul 27, 2020 · 7 comments · Fixed by frictionlessdata/datapackage-v2-draft#41

Comments

@roll
Copy link
Member

roll commented Jul 27, 2020

Overview

For now, we have:

  • a resource describes a data entity
  • a resource can be tabular
    • a tabular resource has schema property that must be Tabular Schema
    • a tabular resource has dialect property that must be CSV Dialect

It means that we have only two mechanisms to add tabular information to the resource: schema and dialect properties:

  • schema: what is the data
  • dialect: how to extract the data

Maybe at some point this list can be extended e.g. providing table filtering ability etc but, as for now, I think we definitely can generalize the dialect property. Instead of having it csv-only we can have a general Table Dialect spec helping describe any tabular format details.

The proposed Table Dialect spec will create a nice symmetry with already existent Table Schema spec. Here is a quick overview of the proposal. The spec is hierarchical so e.g. Csv Table Dialect inherits all the props from Table Dialect.

Table Dialect

Core Table Dialect spec will handle header management.

header (bool)

default: true

Whether the table has a header row(s)

headerRows (int[])

default: [1]

An array of header row numbers. Can describe a multiline header.

headerJoin (str)

default: ' ' (one space)

A string to concatenate a multiline header. Has no effect for a single row header.

Csv Table Dialect

@amercader hints that we also need to re-review the CSVW spec in case we miss something - https://www.w3.org/TR/2015/REC-tabular-metadata-20151217/#dialect-descriptions

It will support all the header options and the options below which is standard for csv.

delimiter (str)

default: ,

lineTerminator (str)

default: \r\n

quoteChar (str)

default: ""

doubleQuote (bool)

default: true

escapeChar (str)

default: not set

nullSequence (str)

default: not set

skipInitialSpace (bool)

default: false

I propose the following changes to the current Csv Dialect spec:

  • make skipInitialSpace=False by default to sync with Python/Pandas/JS/etc behaviour
  • remove caseSensitiveHeader as I guess it should be an option for some infer function but for general data description I'm not sure what it does
  • review commentChar option as partially its role will be handled by headerRows and, at the same time, there is more functional skipRows supported by the software. In software, I've moved all the skip/pick/limit/offset_fields/rows functionality to a separate group called Table Query (or Table Discovery previously) which should probably exist only in software because we don't want to make ETL from the specs, although I think there are options to consider.

Excel Table Dialect

It will support all the header options and:

sheet (str|int)

default: 1

String or integer to address an excel sheet e.g. 2 or Sheet 2.

Options to consider:

  • fillMergedCells
  • preserveFormatting
  • adjustFloatingPointError

Json Table Dialect

It will support all the header options and:

keyed (bool)

default: false

Whether a source is keyed i.e. an array of dictionaries instead of an array of arrays.

keys (str[])

default: not set

For a keyed source, an array of keys to use as a header row.

Options to consider:

  • property (path to the data within json e.g. dogs/data)

In conclusion, the idea is:

  • csv is not the only tabular format; let's describe others, the most importantly Excel
  • to have one hierarchical spec which will help standardize different formats' dialects
  • new formats and properties addition should be considered based on users' demand and should happen gradually
@rufuspollock
Copy link
Contributor

Very interesting proposal and generally big 👍

  • headerRows - we def want something like this - i believe Multi-line header rows #681 is also about this
  • Not sure about headerJoin - can you provide more detail?
  • Like the idea of specializing the dialect to other cases

@roll
Copy link
Member Author

roll commented Jul 27, 2020

Probably I should have put headerJoin into the Options to consider category as it's a very minor and rare case. At the same time, people asked for this option for tabulator many times including for pilots as there are a lot Excel files with "fancy" multiline header like:

excel

So it's basically the way we join a multiline header row:

dialect = ExcelDialect(header_rows=[7, 8, 9], header_join='/')
with Table('excel.xlsx', dialect=dialect) as table:
    print(table.headers)
    # ['Current/Phase1/#', ...]

@rufuspollock
Copy link
Contributor

rufuspollock commented Jul 27, 2020 via email

@rufuspollock
Copy link
Contributor

@roll do you want to start with a pull request to add this as a pattern?

@roll
Copy link
Member Author

roll commented Apr 4, 2021

Sure. I'll PR (can take some time though)

@nichtich
Copy link
Contributor

nichtich commented Dec 18, 2022

Json Table Dialect requires further discussion as many ways exist to encode tabular data in JSON.

  1. array of arrays
  2. array of objects (aka keyed) so order of columns is unknown
  3. object with property for rows and property for header

See https://www.w3.org/TR/csv2json/ (CSVW) for an example of a specification that supports 1 (simple) and 3 (slightly complicated). A simplified form of this uses an object with property rows for rows and property columns with an array of objects, each having property label at least.

So keyed is probably fine but keys is more complex.

Moreover cells in JSON Tables and Excel Tables can have data types other than plain strings.

  • Excel: text, number, logical, error.
  • JSON: any JSON data type except object and possibly array (string, number, boolean, null)

Datatypes can be defined with columns as done in CSVW but less complex (e.g. only string, number, logical).

@roll
Copy link
Member Author

roll commented Dec 23, 2022

Thanks, @nichtich!

I think it should not be a blocker as in specs like this we have a privilege to start from a small core and extend once other properties are discussed and justified

@roll roll added this to the v2 milestone Apr 7, 2023
@roll roll changed the title Proposal: Table Dialect Spec Proposal: File Dialect Spec May 1, 2023
@roll roll changed the title Proposal: File Dialect Spec Proposal: Table Dialect Spec Jul 16, 2023
@roll roll removed the New Spec label Jan 3, 2024
@roll roll changed the title Proposal: Table Dialect Spec Table Dialect Spec Jan 3, 2024
@roll roll added the epic label Jan 25, 2024
@roll roll self-assigned this Feb 21, 2024
@roll roll added the proposal label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants