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

toRecords fails to convert pl.Date values #48

Closed
kymckay opened this issue Mar 9, 2023 · 3 comments
Closed

toRecords fails to convert pl.Date values #48

kymckay opened this issue Mar 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@kymckay
Copy link

kymckay commented Mar 9, 2023

Have you tried latest version of polars?

  • yes

What version of polars are you using?

  • 0.7.2

What operating system are you using polars on?

  • Debian 12

What node version are you using

  • node 18.13.0

Describe your bug.

  • With a pl.Date column in the data frame, using the toRecords function produces objects which have dates at the unix epoch.

What are the steps to reproduce the behavior?

import pl from "nodejs-polars";

let df = pl.DataFrame({
  date: [new Date()],
});

df = df.withColumn(pl.col("date").cast(pl.Date).alias("date"));

console.log(df.toString());
console.log(df.toRecords());

What is the actual behavior?

shape: (1, 1)
┌────────────┐
│ date       │
│ ---        │
│ date       │
╞════════════╡
│ 2023-03-09 │
└────────────┘

{date: Thu Jan 01 1970 01:00:19 GMT+0100 (Greenwich Mean Time)}

What is the expected behavior?

shape: (1, 1)
┌────────────┐
│ date       │
│ ---        │
│ date       │
╞════════════╡
│ 2023-03-09 │
└────────────┘

{date: Thu Mar 09 2023 00:00:00 GMT+0100 (Greenwich Mean Time)}
@kymckay kymckay added the bug Something isn't working label Mar 9, 2023
@Bidek56
Copy link
Collaborator

Bidek56 commented Jun 17, 2023

This works in 0.8.0:

let df = pl.DataFrame({
  date: [new Date()],
});

df = df.withColumn(pl.col("date").date.strftime("%Y-%m-%d").alias("date"));

console.log(df.toString());
console.log(df.toRecords());

shape: (1, 1)
┌────────────┐
│ date       │
│ ---        │
│ str        │
╞════════════╡
│ 2023-06-18 │
└────────────┘
[ { date: '2023-06-18' } ]

@kymckay
Copy link
Author

kymckay commented Jun 18, 2023

I think you have misunderstood, as your example is different since it's just converting a pl.Datetime column into strings.

I'm interested in storing pl.Date type in the dataframe, which should map to Date objects in the records form (pl.Datetime works correctly and can be used as a workaround, but I don't need that precision, just the date).

@Bidek56
Copy link
Collaborator

Bidek56 commented Sep 7, 2023

The code above works fine in 0.8.2, please re-open is this still an issue. Thx

@Bidek56 Bidek56 closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants