Objects

Overview

This week we will see how Python actually works by looking beyond simple functions and into methods, classes, and the outlines of Object Oriented Design and Programming (OOD/OOP). We’ll also look at what to do when ‘things go wrong’, because they will, but sometimes we want that to blow up the application while other times we want Python to handle the ‘exception’ gracefully. Learning to read Exceptions is essential to debugging code: the one thing that almost never works when you get an exception is ignoring it.

Learning Objectives
  1. Develop enough of an understanding of classes and inheritance that you can make effective use of Python.
  2. Develop an understanding of how to read and write Exceptions so as to be able to create robust code.
  3. Under the process of moving code from in-line scripting, to functions, to packages of functions.
  4. Begin developing an appreciation of the substantive concerns of the module (data, ethics, bias, and the risks of ‘experts’ who ‘know it all’).

This week deals with ‘objects’ and ‘classes’, which is fundamental to mastering the Python programming language: in Python, everything is an object, you just didn’t need to know it until now. Understanding how classes and objects work is essential to using Python effectively, but it will also make you a better programmer in any language because it will help you to think about how data and code work together to achieve your goals.

Preparatory Lectures

Come to class prepared to present/discuss:

Session Video Presentation
Methods Video Slides
Classes Video Slides
Design Video Slides
Exceptions Video Slides
More on the Assessments In class Slides

Other Preparation

Readings

Come to class prepared to discuss the following readings:

Citation Article ChatGPT Summary
D’Ignazio and Klein (2020a) Ch.5 URL Summary
Etherington (2016) URL Summary
Lansley (2016) URL N/A

Study Guide

  1. Reading D’Ignazio and Klein (2020a) (Ch.5) reflect on:
  • The authors of “Data Feminism” propose a shift from “data for good” to “data for co-liberation.” Explain the core differences between these two frameworks using examples from the sources.
  • Compare and contrast the data science methodologies employed by the Anti-Eviction Mapping Project (AEMP) and the Eviction Lab. How do their approaches to data collection, cleaning, and analysis reflect different values and priorities? What are the ethical implications of these choices, and how do they relate to the concept of “epistemic violence”?
  • The dominant metaphors used to describe data scientists, such as “unicorns,” “wizards,” and “rock stars,” can reinforce power imbalances in data work. Analyze the implications of these metaphors, and discuss how alternative framings of data science labor could promote more collaborative and equitable practices.
  1. Reading Etherington (2016) reflect on:
  • Why does Etherington advocate for teaching GIS programming to geographers using an open-source Python approach?
  • Describe the six core spatial concepts that Etherington uses to structure his GIS programming course and reflect on whether they improve our understanding of both.
  1. Reading Lansley (2016) reflect on:
  • Why does Lansley introduce a geography researcg article with an extensive review of marketing and advertising literature?
  • How does Lansley segment cars into distinctive categories and what are the implications of this segmentation for understanding the social and economic landscape of the UK?
  • What are some of the limitations of using administrative data, such as DVLA car registration data, to study socioeconomic trends?
  1. Collectively:
  • The sources highlight a tension between the need for “clean” data in analysis and the potential for data cleaning to obscure diversity. Consider specific examples from the sources that illustrate this tension, and analyze how different approaches to data cleaning might impact the representation of ‘outliers’ in the data (be they marginalised groups, or extreme values).
Connections

D’Ignazio and Klein (2020b, Ch.5) will hopefully help you to reorient your thoughts on what it is that data scientists do (are they rock stars or janitors or something else?), while Etherington (2016) will help you to see how spatial and programming concepts can be connected to one another to improve our understanding of both. For a particularly good example of this see the GIS Algorithms text (Xiao 2016).

We’re now going to shift our focus slightly towards more critical takes on data and data science. These are not by people who can’t ‘do’ data science, rather they point to ways in which neither the data, nor the people who process them, are neutral or objective in the way that we often like to think they are.

Practical

Warning

This practical will lead you through the process of converting inline scripts into functions and, ultimately, into a simple package. The last parts of the practical are optional – creating classes in hierarchies is integral to how Python works, but many data scientists will rarely need to write their own classes… they just make use of classes written by others (which is why understanding what they are is important, but being able to write your own is a little less so).

Connections

The practical focusses on:

  • Bedding in the ‘data thinking’ from last week’s practical.
  • Creating functions to perform repetitive tasks.
  • Packaging these functions up and accessing via the appropriate namespace.
  • Implementing a few simple classes so that you understand the basics of how they work.

To access the practical:

  1. Preview
  2. Download

References

D’Ignazio, Catherine, and Lauren F. Klein. 2020a. “Data Feminism.” In. MIT Press. https://data-feminism.mitpress.mit.edu/.
———. 2020b. Data Feminism. MIT Press. https://data-feminism.mitpress.mit.edu/.
Etherington, Thomas R. 2016. Teaching introductory GIS programming to geographers using an open source Python approach.” Journal of Geography in Higher Education 40 (1). Taylor & Francis:117–30. https://doi.org/10.1080/03098265.2015.1086981.
Lansley, Guy. 2016. “Cars and Socio-Economics: Understanding Neighbourhood Variations in Car Characteristics from Administrative Data.” Regional Studies, Regional Science 3 (1). Taylor & Francis:264–85. https://doi.org/10.1080/21681376.2016.1177466.
Xiao, Ningchuan. 2016. GIS Algorithms: Theory and Applications for Geographic Information Science & Technology. Research Methods. SAGE. https://doi.org/https://dx.doi.org/10.4135/9781473921498.