PSF GSoC students blogs: GSoC Weekly Check-in

Hello everyone!

This is 7th week of GSoC 2019, just one week away from 2nd Evaluations. Here’s what I did this week.

What did I do this week?

This week was a bit relaxing. I didn’t do much except making changes in my old PR for improvement of Icons Picker API. Added some features like zipping folders, providing a separate route for download of files and improved file structure. There were a few changes my mentors told me to make in that PR so that the code matches all the other repos. Except that I started working on the current version of EOS-icons while the new version is still in development.

What is coming up next week?

In one or two days the code base for new version of EOS-icons will be ready which brings some major changes like moving to pug from HTML templates, using Gulp instead of Grunt and a lot more. Once that is done, I’ll make the icons-picker and connect it with API.

Did I get stuck anywhere?

Yes, I am still stuck on some error with heroku deployment. I tested it locally and the solution seems to work. Once my PR is merged I’ll try to make the changes in it.

Till next time,
Cheers!

Planet Python

Mike Driscoll: Intro to Black – The Uncompromising Python Code Formatter

There are several Python code checkers available. For example, a lot of developers enjoy using Pylint or Flake8 to check their code for errors. These tools use static code analysis to check your code for bugs or naming issues. Flake8 will also check your code to see if you are adhering to PEP8, Python’s style guide.

However there is a new tool that you can use called Black. Black is a Python code formatter. It will reformat your entire file in place according to the Black code style, which is pretty close to PEP8.


Installation

Installing Black is easy. You can just use pip for that:

pip install black

Now that it’s installed, let’s give Black a try!


Using Black

Black requires you to have some code to run it against. Let’s create a simple function that has lots of parameters and then run Black on that script.

Here’s an example:

def long_func(x, param_one=None, param_two=[], param_three={}, param_four=None, param_five="", param_six=123456):     print("This function has several params")

Now in your terminal, try running black against your code file like this:


black long_func.py

When you run this command, you should see the following output:


reformatted long_func.py
All done! ✨ 🍰 ✨
1 file reformatted.

This means that your file has been reformatted to follow the Black standard.

Let’s open the file up and see what it looks like:

def long_func(     x,     param_one=None,     param_two=[],     param_three={},     param_four=None,     param_five="",     param_six=123456, ):     print("This function has several params")

As you can see, Black has put each of the parameters on their own line.


Checking Files for Formatting

If you don’t want Black to change your file, but you want to know if Black thinks a file should be changed, you can use one of the following command flags:

  • –check – which checks if the file should be reformatted, but doesn’t actually modify the file
  • –diff – which writes out a diff of what Black would do to the file, but doesn’t modify the file

I like to use these to do a test run on my files and see how Black will reformat my code. I haven’t been using Black a long time, so this let’s me see if I like what Black is going to do without actually doing anything.


Wrapping Up

I like Black. I think it could be really useful, especially in an organization when it comes to enforcing a certain Python style. Note that Black defaults to 88 characters for its line length, but you can change that using -l or --line-length if you need to. There are also a few other options you might find useful listed on the project’s page. If you get a chance, I think you should give Black a try!


Related Reading

The post Intro to Black – The Uncompromising Python Code Formatter appeared first on The Mouse Vs. The Python.

Planet Python

Swap Measures Using Parameter Actions

Everybody who has used Tableau for a while has come to love swapping measures by using a parameter. In fact, that is a feature I often utilize to make better use of space on a dashboard and to save time as it allows you to analyse several measures in one area. If you aren’t familiar with the technique, this Tableau Knowledge Base article is a good place to start.

Parameter Actions in the Tableau Toolbox

When I heard that Tableau would finally be adding parameter actions to its Toolbox, i.e. the value of a parameter being driven by a user selection on a dashboard, I got very excited. This new feature would finally make that drop-down menu (where you select a measure to be displayed on the dashboard) obsolete.

One of the issues I always had with the drop-down menu on top of a dashboard was that you don’t see all the possible measure selections at a glance because the others are hidden in the menu. A second issue is that it is hard to make the user aware of which charts will be influenced by the selection.

I will now show how you can change the measure you analyse on your dashboard by just clicking a KPI box rather than selecting from a drop-down menu—I consider this to be the best use case for parameter actions I’ve encountered so far.

1. Create a Parameter containing the Measure names and a Variable Measure (as shown in the Knowledge Base article):

2. Create a calculated field for each Measure in the parameter containing its number (e.g. if Sales is 1 in your parameter, create a calculated field that contains only 1) and turn them into a measure.

Note: You can also use words for your KPIs both in the parameter and the selection fields. Personally, I prefer integers as they give you some more flexibility and remove the possibility of having typos in your words.

3. Create a KPI Box for each Measure and add the respective calculated field to that KPI Box:

4. Place KPI boxes on the dashboard:

5. Create the parameter actions that drive the measure selection. In case you are using an integer parameter like I am, make sure you do not aggregate your Parameter Value calculated field. We just need the actual value of the field that we typed in before:

6. That’s it. Your parameter action now drives the value of the variable measure created before:

I have created an example on Tableau Public that you can download and explore:

The post Swap Measures Using Parameter Actions appeared first on InterWorks.

InterWorks