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

Fix repr on Period Types, and DateTime, Date #30817

Merged
merged 4 commits into from
Jan 28, 2019

Conversation

fchorney
Copy link
Contributor

@fchorney fchorney commented Jan 23, 2019

Jumping off of this previous PR #30200

It seems the Period types face a similar issue. Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, and Nanosecond

julia> using Dates

julia> show(Hour(1))
1 hour

Realistically this should show the equivalent repr type output. Hour(1)

I also noticed that the previous PR that is referenced in this one prints out "DateTime" or "Date" regardless of how Dates was imported. import vs using.

When using import, you would expect

julia> import Dates

julia> show(Dates.Hour(1))
Dates.Hour(1)

and with using, you would expect

julia> using Dates

julia> show(Hour(1))
Hour(1)

@JeffBezanson JeffBezanson added dates Dates, times, and the Dates stdlib module display and printing Aesthetics and correctness of printed representations of objects. stdlib Julia's standard library labels Jan 23, 2019
@JeffBezanson
Copy link
Member

Nice, thank you (and welcome)!

Not directly related, but I also notice Dates defines a few methods for Base.string and then defines print(io, x) = print(io, string(x)), which is redundant. In fact it should only define the print methods, then you get string for free.

base/number.jl Outdated
@@ -314,7 +314,7 @@ julia> oneunit(3.7)
1.0

julia> import Dates; oneunit(Dates.Day)
1 day
Dates.Day(1)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't quite right --- 1 day should still be printed in the REPL, but repr should give Dates.Day(1). The BitPeriod type can be removed, and instead the current show method should be a method show(io::IO, ::MIME"text/plain", p::Period), and your new method might not be necessary since the fallback 2-argument show will probably print Dates.Day(1).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I see what you're saying. I think my latest change should satisfy those requirements, while also satisfying 1 day being shown in outputs such as in a dataframe.

- Given `x = Dates.Day(1)`
 - The REPL will print: `1 day`
 - show will print: `Dates.Day(1)`
 - repr will print: `Dates.Day(1)`
 - print will print: `1 day`
 - string will print: `1 day`
 - dataframes will print: `1 day`
Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

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

Nice work 👍

@fchorney
Copy link
Contributor Author

Looks like the macOS build failed trying to pull a package

Got exception outside of a @test
  failed to clone from https://github.com/JuliaIO/JSON.jl.git, error: GitError(Code:ERROR, Class:Net, curl error: Could not resolve host: github.com)

@omus
Copy link
Member

omus commented Jan 28, 2019

@JeffBezanson does this look good to you?

@JeffBezanson JeffBezanson merged commit a7fabc9 into JuliaLang:master Jan 28, 2019
@fchorney fchorney deleted the fc/fix-time-repr branch February 13, 2019 22:12
omus added a commit to JuliaTime/TimeZones.jl that referenced this pull request Mar 29, 2019
Related to these Dates stdlib changes:

- JuliaLang/julia#30200
- JuliaLang/julia#30817
omus added a commit to JuliaTime/TimeZones.jl that referenced this pull request Mar 29, 2019
* Overhaul printing of types

Related to these Dates stdlib changes:

- JuliaLang/julia#30200
- JuliaLang/julia#30817

* Review comments
KristofferC added a commit that referenced this pull request May 10, 2019
@omus omus mentioned this pull request May 21, 2019
KristofferC pushed a commit that referenced this pull request Sep 6, 2019
KristofferC added a commit that referenced this pull request Sep 6, 2019
JeffBezanson added a commit that referenced this pull request Dec 16, 2019
KristofferC pushed a commit that referenced this pull request Apr 11, 2020
kpamnany pushed a commit to RelationalAI-oss/TimeZones.jl that referenced this pull request May 5, 2023
* Overhaul printing of types

Related to these Dates stdlib changes:

- JuliaLang/julia#30200
- JuliaLang/julia#30817

* Review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module display and printing Aesthetics and correctness of printed representations of objects. stdlib Julia's standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants