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

Add schemas to datasets #7

Merged
merged 10 commits into from
Feb 16, 2024
Merged

Add schemas to datasets #7

merged 10 commits into from
Feb 16, 2024

Conversation

simonhkswan
Copy link
Contributor

@simonhkswan simonhkswan commented Feb 13, 2024

This PR adds dtypes to all of the datasets.

A few datasets were also edited to improve their quality.

removed Unnamed:0:

  • healthcare
  • fire-peril
  • homesite-quotes
  • price-paid-household
  • vehicle-insurance

updated values:

  • air-quality: the Time column was updated to represent timestamps ('12.00.00' -> '12:00:00')
  • household_power: float columns had '?' replaced with ''

@simonhkswan simonhkswan self-assigned this Feb 13, 2024
DType.DOUBLE: st.DoubleType(),
DType.INTEGER: st.IntegerType(),
DType.LONG: st.LongType(),
DType.NULLABLE_LONG: st.FloatType(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be st.LongType() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spark can't read columns that contain [1.0, , 2.0] because of the decimal points :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe with an example I can make more sense:

Say you have a column a table with the following columns:

# some csv file
colA,colB,colC
0,1,1.0
1,,
3,2,2.0
0,1,1.0

Both colA and colB can be read into spark as integers (one being non-null and the other being nullable. But Spark can't read colC as an integer column. Well... it does, but it says everything is Null. i.e.,

+----+----+----+
|colA|colB|colC|
+----+----+----+
|   0|   1| NaN|  
|   1|    |    | 
|   3|   2| NaN| 
|   0|   1| NaN| 
+----+----+----+

So whilst pandas can handle the decimal points, spark cannot. The mapping of Nullable_long to FloatType simply means spark creates the following dataframe which I think is good enough for now! (I think we may want to ultimately rewrite the file)

+----+----+----+
|colA|colB|colC|
+----+----+----+
|   0|   1| 1.0|  
|   1|    |    | 
|   3|   2| 2.0| 
|   0|   1| 1.0| 
+----+----+----+

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I'll set this to map to long instead of float (+ update the yaml config).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

src/synthesized_datasets/__init__.py Show resolved Hide resolved
src/synthesized_datasets/_dtypes.py Outdated Show resolved Hide resolved
src/synthesized_datasets/_datasets.py Show resolved Hide resolved
DType.DOUBLE: st.DoubleType(),
DType.INTEGER: st.IntegerType(),
DType.LONG: st.LongType(),
DType.NULLABLE_LONG: st.FloatType(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spark can't read columns that contain [1.0, , 2.0] because of the decimal points :(

@simonhkswan
Copy link
Contributor Author

tested loading all the datasets aswell:

====================== 110 passed, 4 skipped, 126 warnings in 52.84s =======================

Copy link
Member

@tomcarter23 tomcarter23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks!

@simonhkswan simonhkswan merged commit 8fd344f into master Feb 16, 2024
@simonhkswan simonhkswan deleted the add_schema branch February 16, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants